php: using DomDocument whenever I try to write UTF-8 it writes the hexadecimal notation of it

前端 未结 6 963
清歌不尽
清歌不尽 2020-11-27 21:41

When I try to write UTF-8 Strings into an XML file using DomDocument it actually writes the hexadecimal notation of the string instead of the string itself.

for exam

6条回答
  •  鱼传尺愫
    2020-11-27 22:26

    $doc = new DOMDocument();
    $doc->loadHTML('' . $html);
    
    // dirty fix
    foreach ($doc->childNodes as $item)
      if ($item->nodeType == XML_PI_NODE)
        $doc->removeChild($item); // remove hack
    $doc->encoding = 'UTF-8'; // insert proper
    

提交回复
热议问题