PHP替换xml内容里的号及&符号,使用simplexml_load_string函数,replace

原由:数据库中有写进的XML,但里面格式有如下<dict><name>张三&李四<动><植></name></dict>这种,  simplexml_load_string 函数需先把 张三&李四<动><植> 中的&换成&amp;    ,将<换 &lt;  , 将>换成 &gt;  才能正常运转

我用的是PHP5.4, 在php.ini 中开启 extension=php_tidy.dll

下面是代码

$strXml= tidy_repair_string($strXml, array(

‘output-xml’ => true,

‘input-xml’ => true

), ‘utf8’);

// echo $strXml;

//exit();

 

参考链接:
http://stackoverflow.com/questions/5718457/how-to-read-the-multiple-xml-contents-in-a-file-using-php/5718671#5718671

http://bbs.csdn.net/topics/370138116

http://www.php.net/manual/en/tidy.repairstring.php

Leave a Reply

Your email address will not be published. Required fields are marked *