I have a code that is grabbing the entire results page of a search from a database. I want to only grab and display the contents within the body tags so that I can manipulate the rest of the results page myself. Please advise. Thanks.
You can use DOMDocument to extract the parts of the page that you want.
$html = file_get_contents("some resource");
libxml_use_internal_errors(true); //Prevents Warnings, remove if desired
$dom = new DOMDocument();
$dom->loadHTML($html);
$body = "";
foreach($dom->getElementsByTagName("body")->item(0)->childNodes as $child) {
$body .= $dom->saveHTML($child);
}
echo $body;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With