Extract links of webpage
Why We need to extract links of any webpage?
Extracted link used for SEO. When ever we need other webpage images or other content that time we realize if we have all links of web page so, we can instant get content of pages.
Here i am sharing some php function for making extractor for extracting links of webpage.
PHP Function:
function getAllLinks($link) {
$urlData = file_get_contents($link);
$dom = new DOMDocument();
@$dom->loadHTML($urlData);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for($i = 0; $i < $hrefs->length; $i++){
$href = $hrefs->item($i);
$link = $href->getAttribute('href');
$link = filter_var($url, FILTER_SANITIZE_URL);
if(!filter_var($link, FILTER_VALIDATE_URL) === false){
$urlList[] = $link;
}
}
return array_unique($urlList);
}
pass Url or link :
$link = 'https://www.fruxinfo.com/';
var_dump(getAllLinks($link));
Output:
0 coment�rios: