Forum Moderators: coopster

Message Too Old, No Replies

How do I search a field for certain words?

Like a "contain" statement

         

Clark

10:01 am on Jun 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do I have to use regular expressions? That was the only part of perl I just couldn't deal with. And hope to avoid in php.

I'd like to put a value in a $string. Then test to see if the string *contains* any of the following values:

testa
testb
testc

in any order. If it does then do:

x

Can someone help me with an easy way to do this? Thanks.

jaski

11:20 am on Jun 22, 2003 (gmt 0)

10+ Year Member



ereg() is the function for matching.

or eregi() if it is to be a case insensitive match.

ShawnR

1:23 pm on Jun 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another way is strpos(). It takes 2 arguments (the string you are testing and the substring you are testing for). If the string is found, it returns its position. If not it returns false.

But hey, regular expressions are cool!

Shawn

Clark

5:51 pm on Jun 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. I'm going to use Shawn's suggestion except it will be stripos() for case insensitive.

Regular Expressions are cool once you remember the syntax. I hate trying to remember syntax and even more looking it up :)