note 108461 added to function.strrpos
| From: | kyle at shadowdev dot com | Date: | Fri, 27 Apr 2012 22:30:11 +0000 |
| Subject: | note 108461 added to function.strrpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187384@lists.php.net to get a copy of this message | ||
I was searching around the php.net site and couldn't find a function that combined the ability
of strrpos and arrays, so using a prewritten function on the strpos page
(http://us3.php.net/manual/en/function.strpos.php#105984), I've modified it to pick the last
position of items in an array.
Useful for getting the last position of items like ./?/!/)/]/etc
<?php
function strrpos_arr($haystack, $needle) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $what) {
if(($p = strrpos($haystack, $what))!==false)
if ($p>$pos) $pos=$p; #get the last position of the items in the array
}
if ($pos) return $pos;
else return false;
}
?>
Hopefully this helps someoneout
----
Server IP: 192.41.42.26
Probable Submitter: 96.37.198.132
----
Manual Page -- http://www.php.net/manual/en/function.strrpos.php
Edit -- https://master.php.net/note/edit/108461
Del: integrated -- https://master.php.net/note/delete/108461/integrated
Del: useless -- https://master.php.net/note/delete/108461/useless
Del: bad code -- https://master.php.net/note/delete/108461/bad+code
Del: spam -- https://master.php.net/note/delete/108461/spam
Del: non-english -- https://master.php.net/note/delete/108461/non-english
Del: in docs -- https://master.php.net/note/delete/108461/in+docs
Del: other reasons-- https://master.php.net/note/delete/108461
Reject -- https://master.php.net/note/reject/108461
Search -- https://master.php.net/manage/user-notes.php