I had the following code which works fine on my localhost:
$document = new DOMDocument();
$document->loadHTML($p_result);
$form = $document->getElementsByTagName('form')->item(0);
// Code continues using the $form variable
After same code get updated on outside server, loadHTML()
failed and issued this warning.
Warning: DOMDocument::loadHTML() expects parameter 1 to be a valid path, string given in path/name/to/script.php
Returned NULL as well instead of object so code pretty soon gets to the fatal error.
Note that the contents of $p_result
is absolutely the same on outside server and on my localhost.
But why does it displays that kind of warning and why does it not work?
Doesn't it loadHTML()
expects argument 1 to be a string in the first place?
Why does it say that this method expects parameter 1 to be a valid path
?
Just to make it clear I'm not calling loadHTMLFile()
, I'm calling loadHTML()
.
Thanks.
You're affected by one of PHP bugs. The issue was present only in PHP 5.6.8 and 5.6.9. Most likely you have affected PHP version on the server, and bug-free version on your localhost.
The bug itself forbids all null characters in HTML document you're loading, so as a workaround you may try to remove those (actually not needed) characters before further parsing.