Get Link from a URL using PHP

if you want to fetch all link from a particular URL using PHP. Then you can use following code.

First of all create a php file for submitting  URL lets name it as getUrl.php

<form action="geturl.php" method="post">
Enter URL <input type="text" name="siteurl" value="">
<p style="color:#FF0000;"> [ex. -]</p>
<input type="submit" name="url_list">

You can write code for fetching LINKS on geturl.php

$HTML = file_get_contents($srcurl);
$dom = new DOMDocument();
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i length; $i++)
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
echo '<a href=".$srcUrl." ".$url."="">'.$url.'</a><br>';

you can do many other experiments like
you can save it to database.
you can fetch multiple url.
you can do it using cron job.

Photo by schoschie

This entry was posted in Development, PHP. Bookmark the permalink.

Leave a Reply

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

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.