note 90065 deleted from function.strpos by levim

From: Date: Tue, 22 Jul 2014 03:28:09 +0000
Subject: note 90065 deleted from function.strpos by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-200012@lists.php.net to get a copy of this message
Note Submitter: vbracco at gmail dot com ---- This function find position of first occurrence of any $needles in a string $haystack. Return the position as an integer. If needles is not found, strposa() will return boolean FALSE. <?php function strposa($haystack ,$needles=array(),$offset=0){ $chr = array(); foreach($needles as $needle){ $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 (#200012) next »