Extract URLs from an URL is used in many cases, creating a sitemap extracting website URL is a best example of them.
In this Tutorial I will show you how to Extract URLs from the website, it’s very simple you can easily extract all URLs from a web page using PHP. Here we will provide short and simple code to extract all URLs from a web page in PHP. I have used simple DOM concept to find the html data from URL. file_get_contents and loadHTML is used to retrieve the html for URL and DOMXPath to grab it. This PHP code helps to extract all the links from a web page URL. Find this code below.
PHP Code for get URLs from the website
<?php // Webpage URL $webUrl='http://www.quizwine.com/'; $html = file_get_contents($webUrl); $dom = new DOMDocument(); @$dom->loadHTML($html); // get all the content on the page $xpath = new DOMXPath($dom); // finding the a tag $hrefs = $xpath->evaluate("/html/body//a"); //Loop to display all the links for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); echo $url."<br>"; } ?>
Keywords: How to Extract All URLs from a Web Page using PHP, Find Out All Links In any Website using PHP, How to get all urls from page using php, Find Links on Webpage using PHP, How to get all the page links fro URL using PHP, Use PHP to Crawl Links from Another Website, php, extract links, find links, extract url, find urls, get urls, get links