WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
Categories : PHP, URLs, Regexps
Yeni Setiawan
Date : Aug 21st 2007
Grade : 3 of 5 (graded 6 times)
Viewed : 10050
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Yeni Setiawan
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

I wrote this to be used on my local machine and works as expected.

<?php
function extract_url($main_url){

   
$cek_url = parse_url($main_url);
   
$prefix_url = $cek_url['scheme'].'://'.$cek_url['host'];

   
$f = fopen($main_url,"r");
   
$inputStream = fread($f,65535);
   
fclose($f);
    if (
preg_match_all("/<a.*? href=\"(.*?)\".*?>(.*?)<\/a>/i",$inputStream,$matches)) {
        foreach(
$matches[1] as $link){
            if(!
eregi('mailto:|javascript:|ymsgr:',$link)){
                if(
eregi("http://",$link)){
                   
$url = $link;
                }
                else{
                   
$url = $prefix_url.$link;
                }
                if(
eregi('PHPSESSID',$url)){
                   
$url = explode("PHPSESSID",$url);
                   
$url = substr($url[0],0,-1);
                }
               
$output[] = $url;
            }
        }
    }
    return
array_unique($output);
}

?>


here is example of use:
<?php
$start
= time();
print_r(extract_url("http://dontbe.afraid.la"));
$end = time();

echo
'done in '.($end-$start).' second';
?>


have fun!





PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
How to strip non-alpha characters from a string
Categories : Regexps, PHP
Get the AppStore Ranking for any iPhone App
Categories : PHP, Web Services, Regexps
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
Newbie Notes #7 - Ridiculous regex
Categories : PHP, Beginner Guides, Regexps
grab the result of any calculation you submit to the Google Calculator.
Categories : PHP, Arrays, Web Services, Regexps, Math.
Check if a file exists on a remote FTP server with PHP
Categories : PHP, FTP, Regexps
PHP function which gets all the data from a webpage into a string, we can perform regular expression functions on that data afterwards to get our desired data.
Categories : PHP, URLs, HTML and PHP
URL validator and reformatter
Categories : PHP, URLs
validateEmail 2.0 - upgraded version of the old validateEmail function used to validate email addresses via SMTP and regex.
Categories : Email, Regexps, PHP
getting the name of the current script and query string
Categories : PHP, Global Variables, Variables, URLs
Making sure a string containes only digits or no digits.
Categories : Strings, PHP, Regexps
PHP Youtube Downloader - This is a set of PHP functions that can be used to download movies from Youtube.com.
Categories : PHP, CURL, Regexps
a PHP Function to Get only the filename (remove the extension) using regular expressions.
Categories : PHP, Regexps, Beginner Guides
Proper way to do a header redirection with PHP.
Categories : PHP, Headers, URLs