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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With