|
|
|
| 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.
|
|
| |
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 | |
|
|