How can I get a div content in php



PHP Snippet 1:

$dom = new DOMDocument();

$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$divContent = $xpath->query('//div[@id="product_list"]');

PHP Snippet 2:

$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$result = '';
foreach($xpath->evaluate('//div[@id="product_list"]/node()') as $childNode) {
  $result .= $dom->saveHtml($childNode);
}
var_dump($result);

PHP Snippet 3:

string(74) "
      <div>
       bla bla bla
      </div>
      bla bla          
"

PHP Snippet 4:

$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
var_dump(
  $xpath->evaluate('string(//div[@id="product_list"])')
);

PHP Snippet 5:

string(63) "

       bla bla bla

      bla bla          
"