<?php
// Fetch <div id="foobar"> from a webpage
$html = new DOMDocument(); 
$html->loadHtmlFile('http://example.com/some_page.html'); 
 
$xpath = new DOMXPath($html); 
$items = $xpath->query("//div[@id='foobar']"); // replace with your query

$dom = new DOMDocument;
foreach ($items as $item) {
    $dom->appendChild($dom->importNode($item,true));
}

// Output to screen
echo $dom->saveHTML();