PHP DOM loadHTML () method unusual warning

I had the following code that 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 the same code is updated on the front-end server loadHTML()

crashed and throws this warning.

Warning:  DOMDocument::loadHTML() expects parameter 1 to be a valid path, string given in path/name/to/script.php

      

The return is NULL, not an object, so the code gets caught in a fatal error pretty soon.

Please note that the content is $p_result

exactly the same on the front-end server and on my localhost.

But why is it displaying such a warning and why is it not working?

Doesn't match loadHTML()

argument 1 as a string?

Why does he say this method expects parameter 1 to be a valid path

?

Just to make it clear that I am not calling loadHTMLFile()

, I am calling loadHTML()

.

Thank.

+3


source to share


1 answer


You are affected by one of the PHP errors . The problem was only present in PHP 5.6.8 and 5.6.9. Most likely you have affected the PHP version on the server and the error free version on your localhost.

The error itself disallows all null characters in the HTML document you are loading, so as a workaround, you might try to remove those (actually unnecessary) characters before parsing further.



$document = new DOMDocument();
$p_result_without_null_chars = str_replace("\0", '', $p_result)
$document->loadHTML($p_result_without_null_chars);

      

+1


source







All Articles