I have the following code snippet - echo'ing $msn gives me the full html output as expected. However, the $dom->loadHTMLFile gives me an exception:
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity
Not sure what i am doing wrong? Its a straightforward piece of code..
$dom = new DOMDocument();
$msn = file_get_contents("http://moneycentral.msn.com/");
echo $msn;
echo "<br><br>";
$html = $dom->loadHTMLFile($msn);
loadHTMLFile takes a path to the file you're trying to load. What you're actually doing is passing it the HTML markup as an argument. Naturally, it fails.
You need to either do
$html = $dom->loadHTMLFile("http://moneycentral.msn.com/");
or
$html = $dom->loadHTML($msn);
What you want is loadHTML
and not loadHTMLFile
. The latter is to open a file, not the content of the file. The value of $msn
contains the content, and not the URL to the file itself.