473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

retrieve all pics from url

Hey guys!
I want to get all pics (.jpg) from a url and I use this code but sometimes
with some urls it doesnt work :(
Anyone can check it out?

$text = implode("", file($url));
$text = eregi_replace("<!--([^-]|-[^-]|--[^>])*-->","", $text);
while (eregi("[:space:]*(img)[:space:]*=[:space:]*([^ >]+)", $text, $regs))
{
$regs[2] = ereg_replace("\"", "", $regs[2]);
$regs[2] = ereg_replace("'", "", $regs[2]);
$regs[2] = preg_replace("/(\s.+)/" , "" , $regs[2]);
if(eregi(".jpg|.jpeg|.jpe",$regs[2])){
echo $regs[2]."<br>";
}
$text = substr($text, strpos($text, $regs[1]) + strlen($regs[1]));
}

Regards
--
Yang
Jul 17 '05 #1
1 1823
Yang Li Ke wrote:

Hey guys!
I want to get all pics (.jpg) from a url and I use this code but sometimes
with some urls it doesnt work :(
Anyone can check it out?

$text = implode("", file($url));
$text = eregi_replace("<!--([^-]|-[^-]|--[^>])*-->","", $text);
while (eregi("[:space:]*(img)[:space:]*=[:space:]*([^ >]+)", $text, $regs))
{
$regs[2] = ereg_replace("\"", "", $regs[2]);
$regs[2] = ereg_replace("'", "", $regs[2]);
$regs[2] = preg_replace("/(\s.+)/" , "" , $regs[2]);
if(eregi(".jpg|.jpeg|.jpe",$regs[2])){
echo $regs[2]."<br>";
}
$text = substr($text, strpos($text, $regs[1]) + strlen($regs[1]));
}


I'd use preg_match_all with something like this (untested):

"/<[ ]*img[^>]*src[ ]*=[ ]*(\"[^\"]+\.jp[e]?g\"|\'[^\']+\.jp[e]?g\'|[^
]+\.jp[e]?g)[^>]*>/i"

I can't guarantee it because it's untested and long, but it should get all .jpg
or .jpeg filenames in image tags, regardless of case, position of the src
attribute, type and/or lack of quotes. It won't pick it up if they've used tabs
or something within the < and >. Also, it'll include directory names, if they
exist, in the filename:

images/hello.jpg
thumbnails/world.jpeg

Oh, and it'll return the quotes, if they exist, so you might want to strip them
off before using the match.
And it won't pick up images used only by javascript (such as mouseovers).

I don't know what you'll do with the names, but if you're going to try to fetch
the images you should be wary of <base> tags.

For example:

<HTML>
<HEAD>
<BASE HREF="http://www.yoursite.com/">
</HEAD>
<BODY>
<IMG SRC="images/foo.jpg">
</BODY>
</HTML>

If the above file is located at http://www.yoursite.com/subdirectory/ then you
might assume the url of the image is
http://www.yoursite.com/subdirectory/images/foo.jpg when it is actually at
http://www.yoursite.com/images/foo.jpg.

Regards,
Shawn

--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Laphan | last post by:
Hi All Could somebody please put me out of my misery re a problem in IE. If you go to www.AstraAccounts.co.uk and click on any of the nav panel folders on the left you may find that the images...
2
by: harold | last post by:
hi guys, i going mad trying to create a page that has the contents of a folder down one frame (pics, in list form) and when i click one of them it opens in the opposing frame. i have it just about...
4
by: Jorntk | last post by:
I have css in a folder name css. so how can this .css file read a pics file from another folder eg, pics/a.jpg. Both css folder and pics folder are located in a folder named project. I know i...
8
by: David. E. Goble | last post by:
Hi all; I have the following code; var picssigs = new Array( "sigs/finished1.jpg", "sigs/foghorn.jpg", "sigs/motto.jpg", "sigs/sig.jpg", "sigs/SWAT.jpg",
1
by: Laphan | last post by:
First of all, my apologies for the xpost. I realise the netiqute, but this query seems to cross the boundaries of both these groups. Basically I have created a small ASP site that allows a user...
0
by: Beau Peep | last post by:
Yo Guys, Need hlp in my probs. Am tryin to insert the pics/movies(clips any formats) in the sql2000 table. Have a table with a field Image. Me love to see any code workin of these. An get...
2
by: jsd219 | last post by:
Hello, i am having problems displaying an image once i have uploaded it. i upload it to a folder and store its name in a database. below is the code to display the image. I have figured out the the...
2
by: prophet | last post by:
I am new to this so sorry for what is probably a simple question... I want to have a picture that changes at random each time you go to the page so that it is different. Thank you
1
by: lionelm2007 | last post by:
I have a longblob field in a table that stores pics and other files. I am developing a Java application that needs to retrieve the files from the database and view them. I know that the longblob...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.