note 25127 added to function.strpos

From: Date: Wed, 11 Sep 2002 14:10:06 +0000
Subject: note 25127 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-36517@lists.php.net to get a copy of this message
In addition to cerium@x2productions.net: I always use the following function instead of strpos: function strpos2 ($s, $needle) { $pos = strpos($s, $needle); if ($pos === false) return -1; else return $pos; } So I can easily use it the following way: $pos = strpos2($string, $needle); if ($pos >= 0) { // found } else { // not found } or also possible: $pos = strpos2($string, $needle); for ($i = 0; $pos >= $i; $i++) { // do until position } Teddy -- http://www.php.net/manual/en/function.strpos.php http://master.php.net/manage/user-notes.php?action=edit+25127 http://master.php.net/manage/user-notes.php?action=delete+25127 http://master.php.net/manage/user-notes.php?action=reject+25127

« previous php.notes (#36517) next »