PHP 8.5.0 Beta 1 available for testing

Voting

: four plus five?
(Example: nine)

The Note You're Voting On

biker dot mike at gmx dot com
8 years ago
Look out for the following gotcha when loading XML from a string:

<?php
$doc
= new \DOMDocument;
$doc->documentURI = $myXmlFilename;
$doc->loadXML($myXmlString);
?>

documentURI is now set to the value of $myXmlFilename, right?

Wrong!

It's set to the current working directory. If you want to manually set documentURI to something other than the CWD, do so AFTER the call to loadXML().

E.g.:
<?php
$doc
= new \DOMDocument;
$doc->loadXML($myXmlString);
$doc->documentURI = $myXmlFilename;
?>

documentURI really is now set to the value of $myXmlFilename.

<< Back to user notes page

To Top