Page 1 of 1

using STRIPOS()

Posted: Sat Oct 09, 2010 1:53 pm
by tcloud
I need to know if a string exists within a string and am using STRIPOS() for that purpose.

Problem -- when the needle string is the first thing in the string, STRIPOS() returns zero or false.

I don't care what function I use, but I need to get a "true" when the needle string is present anywhere in the haystack string, even at location zero.

Is there some way to set up the STRIPOS() statement?

I've tried:

Code: Select all

if ((stripos($title, 'needle') > 0 )
if ((stripos($title, 'needle') = true )
and even

Code: Select all

if ((stripos($title, 'needle') >= 0 )
which returns true for everything, even when the needle string is NOT present.

Any help appreciated -- including a different approach.

thanks,
Tom

Re: using STRIPOS()

Posted: Sat Oct 09, 2010 3:23 pm
by DigitalMind

Code: Select all

if (stripos($title, 'needle') !== false)

Re: using STRIPOS()

Posted: Sat Oct 09, 2010 8:31 pm
by s.dot
Yes, use the !== comparison operator.
This checks type as well.

0 == false //this is true
0 === false //this is not true

http://php.net/manual/en/language.opera ... arison.php