Web Content: Getting All URL in a Web Page


Web Content Tips - Part 7: Do you want to get and show all url in a web page? You can use preg_match_all() like this:
<?php
$url  = "http://localhost:8048/blog/index.php";
$data = file_get_contents($url); 

preg_match_all("/(http|https|ftp):\/\/[^<>[:space:]]+[[:alnum:]#?\/&=+%_]/", $data, $match);

$list = $match[0];

print_r($list);
// result:
//Array ( [0] => http://localhost:8048/blog/tools/js/syntax00.css //[1] => http://localhost:8048/blog/tools/js/shCore00.js 
//[2] => http://localhost:8048/blog/tools/js/shUnobtr.js 
//[3] => http://localhost:8048/blog/tools/js/shBrushB.js 
//[4] => http://localhost:8048/blog/themes/tropical_bird/style.css 
//[5] => http://localhost:8048/blog/themes/tropical_bird/style2.css 
//[6] => http://localhost:8048/blog/index.php 
//[7] => http://localhost:8048/blog/index.php?hal=tell 
//[8] => http://localhost:8048/blog/index.php?hal=about 
//[9] => http://localhost:8048/blog/index.php?hal=ads 
//[10] => http://localhost:8048/blog/banner/sample9.gif 
//[11] => http://localhost:8048/openads/www/delivery/ 
//[12] => https://localhost:8048/openads/www/delivery/ 
//[13] => http://localhost:8048/openads/www/delivery/ck.php?n=a546d7e4&cb=ecfab2804150a801e1d82e84f77b6a9c 
//[14] => http://localhost:8048/openads/www/delivery/avw.php?zoneid=1&cb=ecfab2804150a801e1d82e84f77b6a9c&n=a546d7e4 
//[15] => http://localhost:8048/blog/articles/Web-Content-Reading-Other-Web-Page-P582.html 
//[16] => http://localhost:8048/blog/articles/Web-Content-Reading-Other-Web-Page-P582.html#more 
//[17] => http://localhost:8048/blog/articles/Web-Content-Forcing-Browser-Downloads-P581.html 
//[18] => http://localhost:8048/blog/articles/Web-Content-Forcing-Browser-Downloads-P581.html#more 
//[19] => http://localhost:8048/blog/articles/Web-Content-Calculating-Script-Execution-Times-P580.html 
//[20] => http://localhost:8048/blog/articles/Web-Content-Calculating-Script-Execution-Times-P580.html#more 
//[21] => http://localhost:8048/blog/articles/Web-Content-Protecting-E-mail-Address-P579.html 
//[22] => http://localhost:8048/blog/articles/PHP-Email-Protecting-Email-Address-from-Spam-Collectors-P152.html 
//[23] => http://localhost:8048/blog/articles/Web-Content-Protecting-E-mail-Address-P579.html#more 
//[24] => http://localhost:8048/blog/articles/Web-Content-Changing-URL-Text-become-Active-URL-P578.html 
//[25] => http://localhost:8048/blog/articles/Web-Content-Changing-URL-Text-become-Active-URL-P578.html#more 
//[26] => http://localhost:8048/blog/articles/Web-Content-Displaying-Content-of-File-P577.html 
//[27] => http://localhost:8048/blog/articles/Web-Content-Displaying-Content-of-File-P577.html#more 
//[28] => http://localhost:8048/blog/articles/Zend-Framework-Session-Automatic-Expiration-P576.html 
//[29] => http://localhost:8048/blog/articles/Zend-Framework-Session-Automatic-Expiration-P576.html#more
?>



Bookmark and Share Tag: web content, url Category: PHP Basic Post : April 28th 2008 Read: 3,524

advertisements


blog comments powered by Disqus