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





Related Articles
How to extract Domain Name from Full URL in PHP PHP Extract Tutorial
How to extract only name from domain in PHP PHP Extract Tutorial
How to extract All url from a single page by PHP PHP Extract Tutorial
How to get first Five Line from CSV File PHP Extract Tutorial
How to get first 100 records from a csv file in PHP PHP Extract Tutorial
How to get meta Tag PHP Extract Tutorial
How to get title description image and multiple images from URL PHP Extract Tutorial
How to read a txt file from a zip remote URL PHP Extract Tutorial
How to extract all url from a html single page in PHP PHP Extract Tutorial

Single Articles
Completed PHP Extracting CodePHP Extract Tutorial
A Demo Screenshot in output areaPHP Extract Tutorial

Read Full:
PHP Extract Tutorial
Category:
Web Tutorial
Sub Category:
PHP Extract Tutorial
Uploaded:
1 year ago
Uploaded by:
Admin
Views:
44



Share on: