I am facing problem in removing certain <tr>
from html retrieved from remote page, the main
problem is that html is invalid or broken my code works well on testing on valid well
formatted html but when it comes to the code of the remote page it doesn't work after some
experiments if found that my be because the html code of the remote page is invalid
here is my code :
<?php
//Get the url
$url = "http://lsh.streamhunter.eu/static/section0.html";
$html = file_get_contents($url);
$doc = new DOMDocument(); // create DOMDocument
@$doc->loadHTML($html); // load HTML you can add $html
$xpath = new DOMXpath($doc);
$elements = $xpath->query("//td[contains(., 'desktop')]"); // search td's that contain 'desktop'
foreach($elements as $el){
$parent = $el->parentNode;
$parent->parentNode->removeChild($parent); // remove TR
//$parent->removeChild($el); // remove TD
}
echo $doc->saveHTML(); // save new HTML
?>
it always give me 500 internal server error, although when i test it on well formatted html it works well?
is there any thing i am missing in the code above ? any suggestion to deal with this problem?