PHP - strpos didn't check first word

strpos will return false if your string isn't there. Otherwise, it returns the position of your string.

In this case, 'aa' is at the start of the string, which means that it's at position 0; and 0 evaluates to false.

You need to do a boolean compare on the result:

if(strpos($word, 'aa') === false)

That's because strpos returns the position of the word, in this case 0. 0 is falsey. == does not check for identical matches, === does. So use a triple equals.

It's even in the docs.


strpos is returning 0, as 'aa' is the 0th character. As 0 == false but does NOT === false (it is not boolean), you need to use === instead of ==.

Tags:

Php