note 46733 added to function.strstr

From: Date: Thu, 21 Oct 2004 18:03:25 +0000
Subject: note 46733 added to function.strstr
Groups: php.notes 
Request: Send a blank email to php-notes+get-78894@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.strstr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46733 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46733&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46733&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46733&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46733&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46733&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46733&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46733&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78894) next »