PHP用相应的ascii代码替换特殊字符

时间:2013-04-14 18:42:25

标签: character ascii

我正在寻找一个能够转换相应ascii代码中所有特殊字符的函数! 我会放心!

我有这段代码:

  

< trust:RequestSecurityTokenResponseCollection xmlns:trust =“http://docs.oasis-open.org/ws-sx/ws-trust/200512”>

我想将其转换为

%3Ctrust%3ARequestSecurityTokenResponseCollection+xmlns%3Atrust%3D%22http%3A%2F%2Fdocs.oasis-open.org%2Fws-sx%2Fws-trust%2F200512%22%3E

如果我使用函数urlencode,它会转换

中的字符串
%26lt%3Btrust%3ARequestSecurityTokenResponseCollection+xmlns%3Atrust%3D%26quot%3Bhttp%3A%2F%2Fdocs.oasis-open.org%2Fws-sx%2Fws-trust%2F200512%26quot%3B%3E

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

问题仅限于2个字符: < “

所以我解决了这3行:

$result = urlencode($result);
$result = str_replace ('%26lt%3B','%3C', $result);
$result = str_replace ('%26quot%3B','%22', $result);