Consider that an web page contains following html segment,
<div name="test_div">This is sample text</div>
You can extract data by the DOMDocument is as following:
$html = file_get_contents( $url);
libxml_use_internal_errors( true);
$doc = new DOMDocument;
$doc->loadHTML( $html);
$xpath = new DOMXpath( $doc);
$node = $xpath->query( '//div[@name="test_div"]')->item( 0);
echo $node->textContent;
Hope it will be helpful.