【发布时间】:2013-02-01 14:25:38
【问题描述】:
我发现了几个类似的问题,但到目前为止,没有一个能够帮助我。
我试图在 HTML 块中输出所有图像的“src”,所以我使用DOMDocument()。这种方法确实有效,但我在某些页面上收到警告,我不知道为什么。一些帖子建议隐藏警告,但我更愿意找出生成警告的原因。
警告:DOMDocument::loadHTML(): htmlParseEntityRef: 没有名字 实体,行:10
产生错误的post->post_content 的一个示例是 -
On Wednesday 21st November specialist rights of way solicitor Jonathan Cheal of Dyne Drewett will be speaking at the Annual Briefing for Rural Practice Surveyors and Agricultural Valuers in Petersfield.
<br>
Jonathan is one of many speakers during the day and he is specifically addressing issues of public rights of way and village greens.
<br>
Other speakers include:-
<br>
<ul>
<li>James Atrrill, Chairman of the Agricultural Valuers Associates of Hants, Wilts and Dorset;</li>
<li>Martin Lowry, Chairman of the RICS Countryside Policies Panel;</li>
<li>Angus Burnett, Director at Martin & Company;</li>
<li>Esther Smith, Partner at Thomas Eggar;</li>
<li>Jeremy Barrell, Barrell Tree Consultancy;</li>
<li>Robin Satow, Chairman of the RICS Surrey Local Association;</li>
<li>James Cooper, Stnsted Oark Foundation;</li>
<li>Fenella Collins, Head of Planning at the CLA; and</li>
<li>Tom Bodley, Partner at Batcheller Monkhouse</li>
</ul>
如果有帮助,我可以发布更多post->post_content 包含的示例?
我已暂时允许访问开发站点,因此您可以查看一些示例 [注意 - 已回答问题后无法再访问链接] -
- 错误 - http://test.dynedrewett.com/specialist-solicitor-speaks-at-petersfield-update/
- 没有错误 - http://test.dynedrewett.com/restrictive-covenants-in-employment-contracts/
关于如何解决这个问题的任何提示?谢谢。
$dom = new DOMDocument();
$dom->loadHTML(apply_filters('the_content', $post->post_content)); // Have tried stripping all tags but <img>, still generates warning
$nodes = $dom->getElementsByTagName('img');
foreach($nodes as $img) :
$images[] = $img->getAttribute('src');
endforeach;
【问题讨论】:
-
显示导致错误的行肯定会使调试更容易。
-
???警告在
DOMDocument::loadHTML();,所以导致错误的行是dom->loadHTML(apply_filters('the_content', $post->post_content)); -
您正在解析的内容的第 10 行...
-
好的,和你一起。在一种情况下,它是
James Cooper, Stnsted Oark Foundation;。我确实认为可能是;导致了这个问题,但是将它们全部替换(之前有几个)并没有帮助。 -
@DavidGard 我最好的猜测是在 HTML 中的某处有一个未转义的 & 符号 (
&)。这将使解析器认为我们在实体引用中(例如&copy;)。当它到达;时,它认为实体已经结束。然后它意识到它所拥有的内容不符合实体,因此它发出警告并将内容作为纯文本返回。
标签: php warnings domdocument