PHP SOAP客户端中的特殊字符

时间:2013-06-07 17:00:57

标签: php soap

我在PHP SOAP客户端创建的XML文档中包含文本值,其中包含'(这是一个撇号)。我已经确认编码是ASCII,它应该是有效的UTF-8。我是这样做的:

foreach ($myarrayofstrings as $s){
    echo mb_detect_encoding($s);
}

如果我删除这样的撇号,则服务器接受我的请求。

$myarrayofstrings = str_replace("'", "", $myarrayofstrings);

问题:

我有什么办法可以确保每次都没有str_replace吗?

1 个答案:

答案 0 :(得分:0)

对我来说,总是使用 utf8_encode 功能而不是替换:

$myarrayofstrings = utf8_encode($myarrayofstrings);

但我认为你也可以使用htmlspecialchars

<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;     
?>
相关问题