Extract All Links of a Website

If you want to extract all links of a website, you can use the snippet below:

$html = file_get_contents('http://example.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);

$all_links = $xpath->evaluate("/html/body//a");

for ($i = 0; $i < $all_links->length; $i++) {
       $link = $all_links->item($i);
       $url = $link->getAttribute('href');

       echo $url.'<br />';
}