Follow by Email

Saturday, April 19, 2014

How to get innerhtml by id in php

This following code will bring html element inner html by it's id.


$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);
$newDom = new domDocument;
libxml_use_internal_errors(true);
$newDom->loadHTML($html);
libxml_use_internal_errors(false);
$newDom->preserveWhiteSpace = false;
$newDom->validateOnParse = true;
     
$sections = $newDom->saveHTML($newDom->getElementById('element id'));  
echo $sections;

No comments:

Post a Comment