extracting URLs

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

extracting URLs

Post by xcom923 »

I was wondering if it was possible to extract all URLs from a file and list them. does anyone have an idea on how to do this. pretty much I need to extract URLs from an RSS feed.
MinDFreeZ
Forum Commoner
Posts: 58
Joined: Tue Feb 14, 2006 12:28 pm
Location: Lake Mary, FL

Post by MinDFreeZ »

Code: Select all

<?php 

$page = 0;  
$URL = "http://www.thewebsite.com/thepage";  
$page = @fopen($URL, "r");  
print("Links at $URL<BR>\n");  
print("<UL>\n");  
while(!feof($page)) {  
$line = fgets($page, 255);  
while(eregi("HREF=\"[^\"]*\"", $line, $match)) {  
print("<LI>");  
print($match[0]);  
print("<BR>\n");  
$replace = ereg_replace("\?", "\?", $match[0]);  
$line = ereg_replace($replace, "", $line);  
}  
}  
print("</UL>\n");  
fclose($page);  

?>
... I didn't make this.... but it grabs all the link from a page... and lists them... so it should work for an RSS feed too... probably.
if not, probably a small alteration could be done to make it work.
User avatar
quocbao
Forum Commoner
Posts: 59
Joined: Sat Feb 04, 2006 2:03 am
Location: HCM,Vietnam
Contact:

Post by quocbao »

There are many classes for reading RSS on PHPClasses , you can use one of them :)
xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

Post by xcom923 »

quocbao wrote:There are many classes for reading RSS on PHPClasses , you can use one of them :)
yeah I know that, but RSS was just an example MinDFree's snipet was much more helpfull
Post Reply