note 64157 added to function.strrchr
| From: | sekati at gmail dot com | Date: | Sun, 09 Apr 2006 00:43:23 +0000 |
| Subject: | note 64157 added to function.strrchr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107575@lists.php.net to get a copy of this message | ||
just a small addition to carlos dot lage at gmail dot com note which makes it a bit more useful and
flexible:
<?php
// return everything up to last instance of needle
// use $trail to include needle chars including and past last needle
function reverse_strrchr($haystack, $needle, $trail) {
return strrpos($haystack, $needle) ? substr($haystack, 0, strrpos($haystack, $needle) + $trail) :
false;
}
// usage:
$ns = (reverse_strrchr($_SERVER["SCRIPT_URI"], "/", 0));
$ns2 = (reverse_strrchr($_SERVER["SCRIPT_URI"], "/", 1));
echo($ns . "<br>" . $ns2);
?>
----
Server IP: 216.194.113.175
Probable Submitter: 69.86.226.94
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.strrchr.php
Edit -- http://master.php.net/note/edit/64157
Del: integrated -- http://master.php.net/note/delete/64157/integrated
Del: useless -- http://master.php.net/note/delete/64157/useless
Del: bad code -- http://master.php.net/note/delete/64157/bad+code
Del: spam -- http://master.php.net/note/delete/64157/spam
Del: non-english -- http://master.php.net/note/delete/64157/non-english
Del: in docs -- http://master.php.net/note/delete/64157/in+docs
Del: other reasons-- http://master.php.net/note/delete/64157
Reject -- http://master.php.net/note/reject/64157
Search -- http://master.php.net/manage/user-notes.php