FREE PHP Scripts and Snippets

Ready to use Free PHP scripts and snippets to use in your projects.
All Free Scripts & Snippets Complete PHP Scripts

PHP - Extract all links from a web page

>> Share on Facebook & Impress your friends <<

PHP Script to extract all links from a web page. This PHP Snippet reads the contents of a web page and loops through all links found on the page and prints them.

<?php
// Set error reporting to off
error_reporting(0);


/*
This function extracts all links from any webpage.

You just need to provide the URL of the web page.
*/
function extractLinksFromURL($URL)
{

// Read whole content from the web page
$data=file_get_contents($URL);


// Create a new DOMDocument
$dom = new DOMDocument();
$dom->loadHTML(mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8'));



// Then we loop through all the <A> tags found on the page.
foreach ($dom->getElementsByTagName('a') as $link)
{
  // Now we print all the links found on the web page
  echo "<a href=" . $link->getAttribute("href") . "\" >" . $link->nodeValue. "</a><br>\n";
}



}  // End of function for "Extracting all links from a URL"




// Using the function to Extract all Links from a Web page
// URL of the page
$URL="http://www.php.net";
extractLinksFromURL($URL)


?>


Request Custom Snippet

Just $5 Onwards

 

Previously Ordered Snippets

I want PHP Code to extract URLs of all videos from a YouTube Playlist.
Price $5 Order Now

I want a PHP Code to extract all external links from a webpage.
Price $5 Order Now

I want to extract only the links which has specific class applied on them.
Price $5 Order Now

I want a script which can take a list of URLs and extract all links found on them. The list should not contain repeat URLs. i.e. it should also remove duplicate links.
Price $10 Order Now

I need PHP code to extract all links from html files stored in a folder.
Price $10 Order Now

Random PHP Scripts and Snippets

PHP - Extract all links from a web page

PHP Script to extract all links from a web page. This PHP Snippet reads the contents of a web page...

PHP extract multiple emails from text

PHP Script to scan a text and extract all email ids contained in the text. It outputs email addresses as...

Create URL Slug from text string [PHP]

PHP Script to create URL from string. It retails only URL Safe characters in the strings. So, now easily create...

Make URLs in plain text clickable [PHP]

This is a simple PHP function to parse text provided and automatically hyperlink the links in the text.

Free PHP folder to gallery script

100% Free PHP folder to gallery script. Just give the name of folder and it will generate gallery of all...

PHP Code to list all files in a folder

This PHP Code snippet lists all files in a folder and hyperlinks them accordingly. Very clean, easy to use function....

Extracting all numbers from a String [PHP]

This PHP function extracts all numbers from a String and prints them as a comma separated list of numbers. Ready...

[PHP] generate keywords from text function

This is a simple function written in PHP to generate keywords from any text. Just pass any free text to...