php domdocument保存xml時中文出現(xiàn)亂碼的解決辦法:1、在loadhtml的時候指定編碼,代碼為【$doc->loadhtml(''】;2、通過iconv對輸出的字符重新轉(zhuǎn)換。
php domdocument保存xml時中文出現(xiàn)亂碼的解決辦法:
第一種:在loadhtml的時候指定編碼,下面這段代碼引用自php.net官方文檔中的回復(fù)
$doc = new domdocument();$doc->loadhtml('<?xml encoding="utf-8">' . $html); // dirty fixforeach ($doc->childnodes as $item) if ($item->nodetype == xml_pi_node) $doc->removechild($item); // remove hack$doc->encoding = 'utf-8'; // insert proper第二種方法,通過iconv對輸出的字符重新轉(zhuǎn)換,代碼如下:
echo iconv("utf-8", "gb18030//translit", $dom->savexml($n) );相關(guān)視頻推薦:php編程從入門到精通