日期:2014-05-17 浏览次数:20671 次
//xml局部格式如下 <aa url="www.xxx.com"> <![CDATA[ <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答1</a></font><br/><br/> <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答2</a></font><br/><br/> <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答3</a></font><br/><br/> ]]> </aa>
<aa url="www.xxx.com"> <![CDATA[ <font size="13"<<a href="www.xxx.com?x=s&f=3" target="_blank"<常 见 问 答1</a></font<<br/<<br/< ]]> </aa>
<aa url="www.xxx.com"> <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答1</a></font><br/><br/> <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答2</a></font><br/><br/> <font size="13"><a href="www.xxx.com?x=s&f=3" target="_blank">常 见 问 答3</a></font><br/><br/> </aa>
------解决方案--------------------
之后不要用htmlspecialchars编码
------解决方案--------------------
php.ini中 magic_quotes_gpc()函数是打开的么?自动给引号转义了。。
------解决方案--------------------
用XmlWriter写CDATA数据
------解决方案--------------------
顺便给你粘过来.
$str = <<<XML <root> <url> <![CDATA[ http://www.google.com ]]> </url> <url> <![CDATA[ http://www.yahoo.com ]]> </url> </root> XML; $xml = simplexml_load_string($str,'simpleXMLElement',LIBXML_NOCDATA); header('Content-type: application/xml'); $xw = new XMLWriter(); $xw->openMemory(); $xw->startDocument('1.0','utf-8'); $xw->startElement('root'); foreach ($xml->url as $item){//在循环内修改即可 $xw->startElement('url'); $xw->writeCdata($item.'abc'); $xw->endElement(); } $xw->endElement(); $xw->endElement(); echo $xw->outputMemory();