Horje
How to extract All url from a single page by PHP

Simple way extracts all url from a single page link with PHP


Completed PHP Extracting Code

Use Follow PHP Code
index.php
Example: PHP
<?php
$urlContent = file_get_contents('http://php.net');
$dom = new DOMDocument();
@$dom->loadHTML($urlContent);
$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'); $url = filter_var($url, FILTER_SANITIZE_URL); // validate url if(!filter_var($url, FILTER_VALIDATE_URL) === false){ echo '<a href="'.$url.'">'.$url.'</a><br />'; }
}
?>

A Demo Screenshot in output area

Output should be:

A Demo Screenshot in output area





Category :
Web Tutorial
Sub Category :
PHP Extract Tutorial
Uploaded by :
Admin