How to get all links from a site – PHP

Having a complete list of your site is incredibly important in the current search landscape. You need not use a tool to get all the links of your site. Use the following PHP code to get all the links.

<?php
$html = file_get_contents('http://goaspro.com');
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the links on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
echo $url.'<br />';
}

Kayalvizhi Ganesan

Web developer, Blogger, You-tuber and a learner. I am always open up for learning new things and sharing it with people. This Blog is to share the things which I have learnt. My goal is to help TYRO to become a PRO

Leave a Reply

Your email address will not be published. Required fields are marked *