DOMDocument-> saveHTML()转换& nbsp;太空 [英] DOMDocument->saveHTML() converting   to space

查看:90
本文介绍了DOMDocument-> saveHTML()转换& nbsp;太空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我有

$document = DomDocument->loadHTML($someHTML);
$xPath = new DOMXPath($document);
//
//do some xpath query and processing
//
$result = $document->saveHTML();

我正在处理的html包含 :

The html I am processing contains  :

<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'>&nbsp;</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>

如何防止& nbsp;

推荐答案

替换& nbsp;?与 
,那么当读取htmlDom文档时,它将返回& nbsp;

replace &nbsp; with &amp;nbsp; then when the htmlDom doc is read it will return &nbsp;

这篇关于DOMDocument-&gt; saveHTML()转换&amp; nbsp;太空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆