<?php

$html = '<!DOCTYPE html>
<html>
  <head>
    <title>DOM (Document Object Model)</title>
  </head>
  <body>
    <a href="http://www.google.com">Google</a>
    <a href="http://www.facebook.com">Facebook</a>
    <a href="http://www.youtube.com">YouTube</a>
    <a href="http://www.yahoo.com">Yahoo!</a>
    <a href="http://www.twitter.com">Twitter</a>
  </body>
</html>';


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

for($i; $i<$a->length; $i++) {
$attribute = $a->item($i)->getAttribute('href');
echo $attribute.'<br />';
}

?>