Extract And Display All Links On A Web Page

Description: Given a URl this code will extract and display all links on a web page.

<?PHP
 
$page = 0;
$URL = "http://w3mentor.com/";
$page = @FOPEN($URL, "r");
 
PRINT("Links at $URL<br />\n");
 
PRINT("<ul>\n");
 
WHILE(!FEOF($page)) {
 
     $line = FGETS($page, 255);
 
     WHILE(EREGI("HREF=\"[^\"]*\"", $line, $match)) {
          PRINT("<li>");
          PRINT($match[0]);
          PRINT("<br />\n");
          $replace = EREG_REPLACE("\?", "\?", $match[0]);
          $line = EREG_REPLACE($replace, "", $line);
     }
}
 
PRINT("</ul>\n");
FCLOSE($page);
 
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.