dqrfdl5708 2012-07-06 13:35
浏览 105
已采纳

php htmlspecialchars()无效

I essentially have an xml file in which one attribute is a link which has &'s. I'm unable to parse this with simplexml_load_string so I'm using htmlspecialchars on it before xml parse and htmlspecialchars_decode after xml parse. But this is not working. the xml parse keeps failing. My code is as follows.

public static function parseXMLStr($xml_str) {
            $xml_str=htmlspecialchars($xml_str, ENT_NOQUOTES);
            self::$xml=simplexml_load_string($feature_ban_xml_str);
            if(isset(self::$xml->link)) {

               .....

What is going wrong? Am i understanding something incorrectly?

edit: xml

<?xml version="1.0" encoding="UTF-8"?>
<link>
   <sublink active="true" redirect="http://abc.def.com/abcdef?id=&cId=45&kId=kA16000">
   </sublink>
</link>

I have to add, str_replace('&','&amp;','') and back works well. But I need something robust and not just for &'s

  • 写回答

1条回答 默认 最新

  • douyan1321 2012-07-06 13:52
    关注

    If you want to just to encode the link of the attribute, the you can use url_encode, url_decode

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据