0
我用PHP创建XML文件时,这是输出我得到编码错误节约用PHP(HTML实体)XML文档
error on line 2 at column 165: Encoding error
Below is a rendering of the page up to the first error.
在源我只看到这个
<?xml version="1.0" encoding="UTF-8"?>
<ad_list><ad_item class="class"><description_raw>Lorem ipsum dolor sit amet
这是我使用的代码(strip_shortcodes
是用于删除Wordpress使用的标签的Wordpress功能)。
$xml = new DOMDocument('1.0', 'UTF-8');
$xml__item = $xml->createElement("ad_list");
$ad_item = $xml->createElement("ad_item");
$xml__item->appendChild($ad_item);
$description_raw = $xml->createElement("description_raw", strip_shortcodes(html_entity_decode(get_the_content())));
$ad_item->appendChild($description_raw);
$xml->appendChild($xml__item);
$xml->save($filename);
如果我从description_raw
删除html_entity_decode
功能比全时生成的XML但当时我有这个错误
error on line 6 at column 7: Entity 'nbsp' not defined
Below is a rendering of the page up to the first error.
'' 非XML有效的实体,对其进行解码才是正道。但是你使用了'DOMDocument :: createElement()'的第二个参数。这是破碎的:http://stackoverflow.com/questions/22956330/cakephp-xml-utility-library-triggers-domdocument-warning/22957785#22957785 – ThW