note 90065 modified in function.strpos by danbrown
| From: | danbrown@php.net | Date: | Sat, 04 Apr 2009 17:27:34 +0000 |
| Subject: | note 90065 modified in function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152811@lists.php.net to get a copy of this message | ||
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
?>
--was--
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.
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
http://php.net/manual/en/function.strpos.php