我无法弄清楚如何阻止DOMDocument破坏这些字符.
<?PHP $doc = new DOMDocument(); $doc->substituteEntities = false; $doc->loadHTML('<p>¯\(°_o)/¯</p>'); print_r($doc->saveHTML()); ?>
预期产出:
¯(°_O)/¯
实际产量:
A(A°_O)/ A
我在
http://php.net/manual/en/domdocument.loadhtml.php的评论中找到了一个提示
原文链接:https://www.f2er.com/php/136555.html(评论来自< mdmitry at gmail dot com> 21-Dec-2009 05:02:“你也可以使用这个简单的黑客将HTML加载为UTF-8:”)
只需添加’<?xml encoding =“UTF-8”>‘在HTML输入之前:
$doc = new DOMDocument(); //$doc->substituteEntities = false; $doc->loadHTML('<?xml encoding="UTF-8">' . '<p>¯\(°_o)/¯</p>'); print_r($doc->saveHTML());