Warning: Domdocument::Loadhtml(): Htmlparseentityref: Expecting ';' in Entity,

DOMDocument::loadHTML(): warning - htmlParseEntityRef: no name in Entity

This correct answer comes from a comment from @lonesomeday.

My best guess then is that there is an unescaped ampersand (&) somewhere in the HTML. This will make the parser think we're in an entity reference (e.g. ). When it gets to ;, it thinks the entity is over. It then realises what it has doesn't conform to an entity, so it sends out a warning and returns the content as plain text.

PHP Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity

You probably have an HTML file being referenced by "test" that is being used by new App(), however that HTML file contains errors. Most likely (almost certain) cause is something like <a href="sompage.php?foo=bar&cat=fish">Link</a>. The & in the HREF introduces a character entity, but there is no ; to go with it.

How to loadHTMLFile() when it fails with 'htmlParseEntityRef: no name' error?

If you really must try to parse it, try this:

$html = file_get_contents("http://gisapps.co.union.nc.us/ws/rest/v2/cm_iw.ashx?gid=12339");
$doc = new DOMDocument();
$doc->strictErrorChecking = false;

$xpath = new DOMXpath($doc);
$elements = $xpath->query("//*/div[@class='owner-name']");

if (!is_null($elements)) {
foreach ($elements as $element) {
echo "<br/>[". $element->nodeName. "]";
$nodes = $element->childNodes;
foreach ($nodes as $node) {
echo $node->nodeValue. "\n";

PS: Your XPath was wrong, I fixed it. Your $nodes won't have anything because that DIV element (.owner-name) doesn't have any children.. so you'll need to revise that.

DOMDocument::loadHTML(): Empty string supplied as input

Alright @Bruce..I understand the issue now. What you want to do is test the value of file_get_contents()

ini_set("display_errors", 1);

$article_url = 'http://google.com';
if (isset($article_url)){
$title = 'contact us';
$str = @file_get_contents($article_url);
// return an error
if ($str === FALSE) {
echo 'problem getting url';
return false;

// Continue
$test1 = str_word_count(strip_tags(strtolower($str)));
if ($test1 === FALSE) $test = '0';

if ($test1 > '550') {
echo '<div><i class="fa fa-check-square-o" style="color:green"></i> This article has ' . $test1 . ' words.';
} else {
echo '<div><i class="fa fa-times-circle-o" style="color:red"></i> This article has ' . $test1 . ' words. You are required to have a minimum of 500 words.</div>';

$document = new DOMDocument();
$libxml_previous_state = libxml_use_internal_errors(true);

$tags = array ('h1', 'h2');
$texts = array ();

foreach($tags as $tag) {
$elementList = $document->getElementsByTagName($tag);
foreach($elementList as $element) {
$texts[$element->tagName] = strtolower($element->textContent);

if (in_array(strtolower($title),$texts)) {
echo '<div><i class="fa fa-check-square-o" style="color:green"></i> This article used the correct title tag.</div>';
} else {
echo "no";

So if ($str === FALSE) { //return an error } and don't let the script continue. You could return false like I am doing or just do an if/else.

Related Topics

Leave a reply