Page 1 of 1

need to find out if string contains a list of words

Posted: Sat Jan 07, 2006 1:17 am
by Extremest
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.

Posted: Sat Jan 07, 2006 1:19 am
by IAD

Code: Select all

if(eregi(".jpg",$your_var)){

action

}
?

Posted: Sat Jan 07, 2006 2:03 am
by feyd
there's no real need for a regex.. strpos() would work faster and be easier to understand, likely..

Posted: Sat Jan 07, 2006 2:31 am
by Jenk
and also using ereg* as opposed to preg* is less efficient as well.

Posted: Sat Jan 07, 2006 9:18 am
by Extremest
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.

Posted: Sat Jan 07, 2006 6:14 pm
by feyd
for all that once, that is best served by a regular expression.

/\.(jpe?g|bmp|png|gif)/

for example.

Posted: Sat Jan 07, 2006 6:25 pm
by foobar
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.

Posted: Mon Jan 09, 2006 1:54 am
by Extremest
ok so use preg_match with that regex and if it === 0 then it did not contain it and then write right?

Posted: Mon Jan 09, 2006 2:19 am
by Extremest
ok that works great thank you very much.

Posted: Thu Jan 12, 2006 8:49 pm
by Extremest
just one quick question about that regex. Does this use the "." or jsut the jpg and that.

Posted: Thu Jan 12, 2006 9:32 pm
by feyd
it requires a dot and jpeg, jpg, bmp, png, or gif to follow.

Posted: Thu Jan 12, 2006 10:30 pm
by Extremest
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.