How can i list all links in a webpage ? I tried something but i couldn't do it . I'm waiting your help
Stop trying to reinvent wheels and start searching on Google. Took me 5 seconds: http://www.scriptaty.net/php-scripts/site-mapping-scripts/ Also bookmark this: http://www.phpclasses.org/ (I can't reach it right now but it has pretty much everything already made you will ever need)
I don't have too much php experience. I see a function here. But how will i use it ? It needs parameters but i was thinking it will only want the link that i want to parse. But it wants 4 arguments. Can you write me an example code for me .
It's not easy to help with the information you're providing. You could do something like this. (If I understand you right) function get_urls_of($url) { if (!($content = @file_get_contents($url))) { exit('Could not load page '. $url); } preg_match_all('/((ht|f)tps?:\/\/[^\s\r\n\"\']*)/si', $content, $urls); return $urls[1]; } // Usage example: $urls = get_urls_of('http://www.somepage.com'); print_r($urls); PHP: Untested but should work.
You understood me right this is what i want. There is an error with the code Parse error: parse error, unexpected T_STRING in C:\Program Files\xampp\htdocs\parse.php on line 4 Code (markup):
My code <? function get_urls_of($url) { if (!($content = @file_get_contents($url))) { exit('Could not load page '. $url); } preg_match_all('/((ht|f)tps?:\/\/[^\s\r\n\"\']*)/si', $content, $urls); return $urls[1]; } // Usage example: $urls = get_urls_of('http://www.google.com'); print_r($urls); ?> Code (markup): Line 4: if (!($content = @file_get_contents($url)))
You must be using an old version of PHP or something. It works fine for me. Anyway, give this a try. <?php function get_urls_of($url) { $content = @file_get_contents($url) OR exit('Could not load page '. $url); preg_match_all('/((ht|f)tps?:\/\/[^\s\r\n\"\']*)/si', $content, $urls); return $urls[1]; } // Usage example: $urls = get_urls_of('http://www.google.com'); print_r($urls); ?> Code (markup):
Thank you very much for the code I wasted 24 hours for creating a new one Then only I Searched DP and found this code! It will be helpful if some one explains this