DOMDocument::loadHTML():警告-htmlParseEntityRef:实体中没有名称 - php

我发现了几个类似的问题,但到目前为止,没有一个能够帮助我。

我正在尝试在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;

参考方案

这个正确答案来自@lonesomeday的评论。

那么,我最好的猜测是,HTML的某处有一个未转义的“&”号。这将使解析器认为我们在实体引用中(例如©)。到达;时,它认为实体已结束。然后,它意识到不符合实体的内容,因此发出警告并以纯文本形式返回内容。

PHP getallheaders替代 - php

我正在尝试从服务器上的apache切换到nginx。唯一的问题是我在PHP脚本中使用的getallheaders()函数,该函数不适用于Nginx。我已经尝试过用户在getallheaders函数上的php站点上提供的注释,但这并不返回所有请求标头。请告诉我如何解决这个问题。我真的想切换到Nginx。 参考方案 您仍然可以使用它,但是您必须像这里一样重新定义…

警告:尝试分配非对象的属性,但是对象存在 - php

这是我的课:class Network { protected $value = null; protected $properties = array(); public $type = null; function __construct($value = null, $type = null) { $this->value = $value; $…

php Singleton类实例将在多个会话中保留吗? - php

举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…

PHP:将字符串拆分为字母和数字部分的最佳方法 - php

我有几个格式的字符串AA11 AAAAAA1111111 AA1111111 分离字符串的字母和数字部分的最佳方法(最有效)? 参考方案 如果它们都是一系列字母,然后是一系列数字,并且没有非字母数字字符,那么sscanf()可能比regexp更有效$example = 'AAA11111'; list($alpha,$numeric) =…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…