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