PHP Warning: DOMDocument::load(): I/O warning : failed to load external entity

2014-10-06 05:59:28 -0400
If you are seeing this error:

PHP Warning: DOMDocument::load(): I/O warning : failed to load external entity in xxx.php on line x
PHP Notice: Trying to get property of non-object in yyy.php on line y

You have 2 solutions:

## Solution 1

Update

//Let the DOMDocument to read the XML file
$doc = new DOMDocument();
$doc->load($fileLocation);

to

//Read the XML contents and give it to DOMDocument
$doc = new DOMDocument();
$xmlContents = file_get_contents($fileLocation);
$doc->loadXML($xmlContents);


## Solution 2 (Warning: this is insecure)

Add this line to the top of your php file:

libxml_disable_entity_loader(false);


But be careful with solution 2 as it will bring in the XML external entity injection attack
«Newer      Older»
Comment:
Name:

Back to home

Subscribe | Register | Login | N