Search code examples
phpif-statementstrpos

PHP - Using strpos To Find a Sting Returning Wrong Result


I'm getting a strange result for using Strpos -

The $tmp variable is pulling all field results from a Mysql Table. For simplicity I'll shorten to just this variable

$tmp = "As Chat Buddies, Through Personal Email, Through Text Messaging" ;

Var_dump $tmp will display the above for example..

I'm using this command..

if (($label == 'Communication') AND (strpos($tmp, 'As Chat Buddies') !== 'false') )
        {
            $tmp .= '&nbsp;<img src="http://www.test.com/image/chat.jpg">';

            }

This works and displays the image in the right section.

This issue is .. The next command in the order ( and any additional commands)...

if (($label == 'Communication') AND (strpos($tmp, 'In Real Life') !== 'false') )
        {
            $tmp .= '&nbsp;<img src="http://www.test.com/image/real.jpg">';

            }

Will also be displayed.. even though it its not in the string anywhere? Its returning as valid regardless.

Any advice?


Solution

  • false should be the constant, not a quoted string As @markbaker Mentioned Above