Page 1 of 1

Image link counting & listing from a remote page

Posted: Sun Nov 12, 2006 9:13 pm
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]

Posted: Sun Nov 12, 2006 9:26 pm
by feyd
preg_match_all() may be more useful in this case.