You should have a look at this class: PHP Simple HTML DOM it works this way:
include('simple_html_dom.php');
$html = file_get_html('http://www.codeigniter.com/');
echo $html->find('title', 0)->innertext; // get <title>
echo "<pre>";
foreach($html->find('meta') as $element)
echo $element->name . " : " . $element->content . '<br>'; //prints every META tag
echo "</pre>";