phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Web Content: Getting All URL in a Web Page

Tag: web content, url   Category: PHP Basic
post: 28 Apr 2008 read: 159


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



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting