4

It's returning

( ! ) Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Misplaced DOCTYPE declaration in Entity, line: 3 in C:\wamp\www\source.php on line 8

The code:

<?php

    $url = "http://www.some-plain-html-website.com";

    $content = file_get_contents($url);

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

?>

For some reason it wont parse $content. If i make content a string like $content = ""; and i parse it by element tag name it works no problem however if i give it the return of file_get_content() method it yields that error.

The documentation for file_get_contents() says it returns a string but for some reason its not working i even tried $content = (string)file_get_contents($url);

Same thing thanks in advance for all the help.

2 Answers 2

10

In many cases it is advisable to use libxml_use_internal_errors(true); before $dom->loadHTML($content);

This way a warning will not be thrown, and the page is loaded anyway.

Sign up to request clarification or add additional context in comments.

Comments

2

The html page you are trying to grab is malformed. The document type declaration must be the first line of a document. You could try cutting the first two lines off of the content before loading it with loadHTML().

1 Comment

Look through the PHP documentation for how to manipulate strings.........................

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.