Author Topic: How to check if a variable has a certain phrase or symbol in it?  (Read 612 times)

How do I check if a variable has a certain phrase or symbol in it?

strpos (or stripos if you need case-insensitivy) will return -1 if the string wasn't found, or the starting position if it wasn't found

For example, strpos("this is an example","x") will return 12, while
strpos("this is an example","q") will return -1
It works for longer phrases or multiple words as well as single characters
« Last Edit: August 22, 2012, 08:08:09 PM by Headcrab Zombie »


You can also use strStr(), it does the exact same thing as strPos() but without the support for an optional search offset. You should use strPos all the time, but I'm just saying it so that you'll know

Should be noted that strPos is case sensitive, and striPos is not.

Should be noted that strPos is case sensitive, and striPos is not.
it was noted
strpos (or stripos if you need case-insensitivy)

Oh, wow. I missed that even after I reread his post when you quoted him. My bad.