Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
Extremest
Forum Commoner
Posts: 84 Joined: Mon Aug 29, 2005 12:39 pm
Post
by Extremest » Sat Jan 07, 2006 1:17 am
I have a list of urls. I need to check the them to see if they contain .jpg or .png stuff like that. So that i can skip them. So like an if with that as the expression for the if. If it doesn't contain them I can have them put into the db. Can anyone please help me with this.
IAD
Forum Commoner
Posts: 42 Joined: Wed Dec 28, 2005 12:36 pm
Location: Israel, Soon Canada :)
Post
by IAD » Sat Jan 07, 2006 1:19 am
Code: Select all
if(eregi(".jpg",$your_var)){
action
}
?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jan 07, 2006 2:03 am
there's no real need for a regex..
strpos() would work faster and be easier to understand, likely..
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Sat Jan 07, 2006 2:31 am
and also using ereg* as opposed to preg* is less efficient as well.
Extremest
Forum Commoner
Posts: 84 Joined: Mon Aug 29, 2005 12:39 pm
Post
by Extremest » Sat Jan 07, 2006 9:18 am
ok strpos works. Now here is a dumb question. How can I have it check for multiple needles. Like check for .jpg,.jpeg,.bmp,.png etc. All of them at once and if it contains none of them then it can write.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jan 07, 2006 6:14 pm
for all that once, that is best served by a regular expression.
/\.(jpe?g|bmp|png|gif)/
for example.
foobar
Forum Regular
Posts: 613 Joined: Wed Sep 28, 2005 10:08 am
Post
by foobar » Sat Jan 07, 2006 6:25 pm
feyd wrote: for all that once, that is best served by a regular expression.
/\.(jpe?g|bmp|png|gif)/
for example.
Yea, or just cycle through them and put it in strpos() every time.
Extremest
Forum Commoner
Posts: 84 Joined: Mon Aug 29, 2005 12:39 pm
Post
by Extremest » Mon Jan 09, 2006 1:54 am
ok so use preg_match with that regex and if it === 0 then it did not contain it and then write right?
Extremest
Forum Commoner
Posts: 84 Joined: Mon Aug 29, 2005 12:39 pm
Post
by Extremest » Mon Jan 09, 2006 2:19 am
ok that works great thank you very much.
Extremest
Forum Commoner
Posts: 84 Joined: Mon Aug 29, 2005 12:39 pm
Post
by Extremest » Thu Jan 12, 2006 8:49 pm
just one quick question about that regex. Does this use the "." or jsut the jpg and that.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 12, 2006 9:32 pm
it requires a dot and jpeg, jpg, bmp, png, or gif to follow.
Extremest
Forum Commoner
Posts: 84 Joined: Mon Aug 29, 2005 12:39 pm
Post
by Extremest » Thu Jan 12, 2006 10:30 pm
ok just wanted to make sure. I have everything working so far in my spider but for some reason apache will crash after a little while with a memory read error. Also get a warning on my index value in an array. Will figure those arrays out gradually.