471,319 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

finding the full path of an image ?

I want to list all images from a url.

here is my code snippet which finds an image from a url:

$url = "http://asdf.com/";

$text = @implode("", file($url));

while (eregi("[:space:]*(src)[:space:]*=[:space:]*([^ >]+)", $text , $regs))
{
echo $regs[2];
$text = substr($text, strpos($text, $regs[1]) + strlen($regs[1]));
}

the only problem is that I would like to have it full path but sometimes I
get stuff like:

"../images/test.jpg"

how can I get all images with full path ?
Jul 17 '05 #1
1 1596
Yang wrote:
while (eregi("[:space:]*(src)[:space:]*=[:space:]*([^ >]+)", $text ,
$regs)) {
echo $regs[2];
$text = substr($text, strpos($text, $regs[1]) + strlen($regs[1]));
}

This will also catch links like:

<script src='foo.js' />
the only problem is that I would like to have it full path but
sometimes I get stuff like:

"../images/test.jpg"

how can I get all images with full path ?


What you could do, is prepend the host and the path and apply preg_replace
in a while loop to replace "dirname/.." sections as follows:

$url = "http://www.example.com/somedir/../images/test.jpg";

while (strstr($url, "/../")) {
$url = preg_replace("|/[^/]+/\.\./|", "/", $url);
}

However, there are more rules to consider. Per example, links like
"//images.example.com/images/whatever.gif". In this case, you should only
preprend "http:" to make the link valid.

The following file gives you an idea:

http://playground.jwscripts.com/imagegrab.phps
JW

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hal Vaughan | last post: by
11 posts views Thread by Fuzzyman | last post: by
3 posts views Thread by Bill Brother | last post: by
2 posts views Thread by Nathan Sokalski | last post: by
4 posts views Thread by m | last post: by
5 posts views Thread by Jay | last post: by
2 posts views Thread by =?Utf-8?B?U2hhbQ==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.