Find links in a website without REGEX parsing

Everybody has needed it before... Website parsing for specific tags.
Naturally everbody try to solve this via REGEX. But how can we do that smarter? The solution is the domDocument class in PHP. This can be used to parse all Elements from HTML Code. In this Example i have used links.

Lets explain this via code:

 
// a site to search for links
$link = 'http://www.php.net';
// get the html code via file_get
$html = file_get_contents($link);
$ret = array();
// create a new dom object
$dom = new domDocument;
 
// load the HTML in the dom class, suppress parsing errors with @
@$dom->loadHTML($html);
 
// get all anchors from the html code
$anchor = $dom->getElementsByTagName('a');
 
/*** get the url from the links ***/
foreach ($anchor as $tag)
{
	// in $tag->getAttribute('href') is the url from the anchor
	// $tag->childNodes->item(0)->nodeValue is the value inside <a>value</a>
	echo $tag->childNodes->item(0)->nodeValue
	echo  ' -> '. $tag->getAttribute('href') . PHP_EOL;
}