note 8602 deleted from function.strpos by jimw

From: Date: Thu, 18 Oct 2001 21:25:39 +0000
Subject: note 8602 deleted from function.strpos by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19126@lists.php.net to get a copy of this message
There seems to be a much easier way to deal with the "did the function return a 0 as position or a FALSE (there was no match)" issue. Since the real issue is that the same numeric value is returned by the program in both of those cases, eliminate one of the two as a possibility. Instead of: strpos ($haystack, $needle) and having to test a resulting 0 further, instead: strpos (" " . $haystack, $needle) Your resulting position will be one higher than the real position (which is easy to compensate for in following code); zero will be returned ONLY in the case of non-match, whereas 1 will be the lowest position marker. It should be noted that it is important to pick a character which is -not- in your $needle when prepending that character (I used space here only as an example; if space were our needle, we would receive an incorrect result).

« previous php.notes (#19126) next »