RE: [PHP] strpos error (I'm missing something obvious)

From: Date: Tue, 02 Oct 2007 13:34:36 +0000
Subject: RE: [PHP] strpos error (I'm missing something obvious)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-262637@lists.php.net to get a copy of this message
[snip] > !== FALSE is not good either, it is not a valid test > > strpos returns the numeric position of the first occurrence of needle in > the haystack string. Except when needle doesn't occur in string, in which case "If needle is not found, strpos() will return boolean FALSE." Checking strpos($foo,$bar) !== False is exactly right; since 0 == False, you want to use !==, not !=. [/snip] If the string is in the first position does it not return a zero? $needle = "a"; $haystack = "abcdef"; echo strpos($haystack, $needle); returns 0 0 is not equal to false. But you are correct, if the string is not found it returns the Boolean false, I should have been clearer.

« previous php.general (#262637) next »