note 92333 deleted from function.strpos by danbrown

From: Date: Mon, 20 Jul 2009 11:27:45 +0000
Subject: note 92333 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158502@lists.php.net to get a copy of this message
Note Submitter: david at mainsip dot com ---- To dpharris at llu dot edu, Your correction doesn't take into account the second test case (needle at 0-pos) due to the if condition not using !== operator. My correction of your correction: <?php function strposa($haystack ,$needles=array(),$offset=0){ $chr = array(); foreach($needles as $needle){ if (strpos($haystack,$needle,$offset) !== false) { $chr[] = strpos($haystack,$needle,$offset); } } if(empty($chr)) return false; return min($chr); } $string = "This is my string, very simple."; echo strposa($string,array(".",","," ")); // 2 echo strposa($string,array("T")); // 0 echo strposa($string,array("Q","W")); // false ?>

« previous php.notes (#158502) next »