【发布时间】:2015-02-02 03:19:11
【问题描述】:
这很奇怪,但看起来 $dom->saveHTML() 正在从内联 javascript 中剥离标签
$domStr = '
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>my page</title>
<script>
var elem = "<div>some content</div>";
</script>
</head>
<body>
<div>
MY PAGE
</div>
</body>
</html>
';
$doc = new DOMDocument();
libxml_use_internal_errors(true);//prevents tags in js from throwing errors; see php.net manual
$doc->formatOutput = true;
$doc->strictErrorChecking = false;
$doc->preserveWhiteSpace = true;
$doc->loadHTML($domStr);
echo $doc->saveHTML();
exit;
http://sandbox.onlinephpfunctions.com/code/ad59a2a1016b2128e437ef61dbe00f1c511bff8d
如果你使用 libxml_use_internal_errors(true);你不会看到有什么问题,但如果删除你会得到 p>
<b>Warning</b>: DOMDocument::loadHTML(): Unexpected end tag : div
同样的事情发生在
$doc->formatOutput = false;
感谢任何帮助。
【问题讨论】:
标签: javascript php domdocument