note 46733 deleted from function.strstr by betz

From: Date: Wed, 03 Nov 2004 16:39:16 +0000
Subject: note 46733 deleted from function.strstr by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79554@lists.php.net to get a copy of this message
Note Submitter: ---- vincents in_str function will work most of the time, but will fail under circumstances, most notably when working with string '0' (zero) consider this: <?php $needle = '0'; $haystack = '1234567890'; if (in_str($haystack, $needle)) { echo "The haystack contains $needle"; } ?> you can clearly see that string 0 is definately in haystack, but the function will return false. a faster, and failproof way would be <?php if (false !== strpos($haystack, $needle) { // we found it } // case insesnitive version if (false !== stripos($haystack, $needle) { // we found it, case insesitive. } ?> this is written on the strpos() page http://php.net/strpos and mentioned on the strstr() page http://php.net/strstr

« previous php.notes (#79554) next »