note 104576 added to function.strpos
| From: | a at bc dot de | Date: | Thu, 23 Jun 2011 15:32:58 +0000 |
| Subject: | note 104576 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180892@lists.php.net to get a copy of this message | ||
A simple way to get the FIRST occurence of any $needle.
Needed if more than one $needle could occur in $haystack and you want the first occurence of any
$needle.
<?php
function strpos_arr($haystack, $needle) {
$First = strlen($haystack);
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $what) {
$pos = strpos($haystack, $what);
if($pos !== false)
{
if($pos < $First) $First = $pos;
}
}
return $First == strlen($haystack) ? false : $First;
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 217.94.59.114
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/104576
Del: integrated -- https://master.php.net/note/delete/104576/integrated
Del: useless -- https://master.php.net/note/delete/104576/useless
Del: bad code -- https://master.php.net/note/delete/104576/bad+code
Del: spam -- https://master.php.net/note/delete/104576/spam
Del: non-english -- https://master.php.net/note/delete/104576/non-english
Del: in docs -- https://master.php.net/note/delete/104576/in+docs
Del: other reasons-- https://master.php.net/note/delete/104576
Reject -- https://master.php.net/note/reject/104576
Search -- https://master.php.net/manage/user-notes.php