1
一个相关的问题是Preventing DOMDocument::loadHTML() from converting entities但它没有产生一个解决方案。DOMDocument:loadHTML()正在转换htmlentities
此代码:
$html = "<span>🆃🅴🆂🆃</span>";
$doc = new DOMDocument;
$doc->resolveExternals = false;
$doc->substituteEntities = false;
$doc->loadhtml($html);
foreach ($doc->getElementsByTagName('span') as $node)
{
var_dump($node->nodeValue);
var_dump(htmlentities($node->nodeValue));
var_dump(htmlentities(iconv('UTF-8', 'ISO-8859-1', $node->nodeValue)));
}
产生以下HTML:
string(16) ""
string(16) ""
string(0) ""
但我要的是🆃🅴🆂🆃
我运行PHP版本29年6月5日和ini_get("default_charset")
回报UTF-8