I had a problem with loading HTML including null bytes, and I applied the bug fix as shown here: PHP DOM loadHTML() method unusual warning
The thing is that now, any query I do on that "fixed" HTML will give no results at all.
This is what I do:
$opts = array('http' => array('header' => 'Accept-Charset: UTF-8, *;q=0'));
$context = stream_context_create($opts);
$html=file_get_contents('http://actualidad.rt.com/ultima_hora',false,$context);
$html=mb_convert_encoding($html, 'UTF-8', mb_detect_encoding($html, 'UTF-8, ISO-8859-1', true));
$html=str_replace("\0", '', $html); //Avoid PHP BUG https://stackoverflow.com/questions/30925533/php-dom-loadhtml-method-unusual-warning
$this->dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath=new DOMXPath($this->dom);
$COUNTDIVS=$xpath->query('//div');
$COUNTDIVS has zero elements, while the real HTML has a whole bunch of div tags.
And, the code is working fine with websites where the bug doesn't apply.
How could I fix it?
Thanks a lot.