note 92333 added to function.strpos

From: Date: Mon, 20 Jul 2009 11:25:54 +0000
Subject: note 92333 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-158500@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 80.64.47.13 Probable Submitter: 80.38.31.101 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/92333 Del: integrated -- https://master.php.net/note/delete/92333/integrated Del: useless -- https://master.php.net/note/delete/92333/useless Del: bad code -- https://master.php.net/note/delete/92333/bad+code Del: spam -- https://master.php.net/note/delete/92333/spam Del: non-english -- https://master.php.net/note/delete/92333/non-english Del: in docs -- https://master.php.net/note/delete/92333/in+docs Del: other reasons-- https://master.php.net/note/delete/92333 Reject -- https://master.php.net/note/reject/92333 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158500) next »