警告:DOMDocument :: loadHTML():htmlParseEntityRef:期待';'在实体中 [英] Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,

查看:312
本文介绍了警告:DOMDocument :: loadHTML():htmlParseEntityRef:期待';'在实体中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$html = file_get_contents("http://www.somesite.com/");

$dom = new DOMDocument();
$dom->loadHTML($html);

echo $dom;

抛出

Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,
Catchable fatal error: Object of class DOMDocument could not be converted to string in test.php on line 10

推荐答案

要消除该警告,可以使用

To evaporate the warning, you can use libxml_use_internal_errors(true)

// create new DOMDocument
$document = new \DOMDocument('1.0', 'UTF-8');

// set error level
$internalErrors = libxml_use_internal_errors(true);

// load HTML
$document->loadHTML($html);

// Restore error level
libxml_use_internal_errors($internalErrors);

这篇关于警告:DOMDocument :: loadHTML():htmlParseEntityRef:期待';'在实体中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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