Image link counting & listing from a remote page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ozz
Forum Commoner
Posts: 26
Joined: Wed Aug 21, 2002 11:47 pm

Image link counting & listing from a remote page

Post by Ozz »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I need to count and list image links from a remote page.
I tried this code:

Code: Select all

$url = "http://www.siteurl.com/page.html";
$file = fopen ("$url", "r");
if (!($file)) 
{
echo "Not exist!";
exit;
}
while (!feof ($file)) {
   $line = fgets ($file, 1024);
   if (eregi ("HREF=\"(.*).jpg\">", $line, $out)) {
       $image = $out[1].".jpg";
       $pos = strpos($image, "http://");
if ($pos === false) {
   $image_url = dirname($url)."/".$image;
}
       
echo $image_url;
}
}


But it's not working stable on different sites especially only works if the image link codes are on one line.

Can anyone suggest any code for listing image links?

Thanks in advance.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

preg_match_all() may be more useful in this case.
Post Reply