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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?