在我的代码中,我有
$document = DomDocument->loadHTML($someHTML);
$xPath = new DOMXPath($document);
//
//do some xpath query and processing
//
$result = $document->saveHTML();
我正在处理的html包含:
<html>
<body>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none"><b><span style='font-size:9.0pt;font-family:"ArialNarrow","sans-serif";
color:red'> </span></b></p>
</body>
</html>
并导致:
<html>
<body>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none"><b><span style='font-size:9.0pt;font-family:"ArialNarrow","sans-serif";
color:red'> </span></b></p>
</body>
</html>
如何阻止
转换为空格?
答案 0 :(得分:3)
$someHTML = str_replace (' ', '@nbsp;', $someHTML);
$document = DomDocument->loadHTML($someHTML);
$xPath = new DOMXPath($document);
//
//do some xpath query and processing
//
$result = $document->saveHTML();
$result = str_replace ('@nbsp;', ' ', $result);
答案 1 :(得分:0)
替换&amp; nbsp;与&amp; amp; nbsp; 然后当读取htmlDom文档时,它将返回&amp; nbsp;