Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP DOM loadHtmlFile I/O exception

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);
like image 949
ChicagoDude Avatar asked Apr 15 '26 01:04

ChicagoDude


1 Answers

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);
like image 95
GordonM Avatar answered Apr 17 '26 16:04

GordonM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!