note 66306 added to function.strrchr
| From: | repleyatfreemaildotit at osu1 dot php dot net | Date: | Thu, 18 May 2006 22:09:19 +0000 |
| Subject: | note 66306 added to function.strrchr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111621@lists.php.net to get a copy of this message | ||
Get file name and extension into an array with or without dot, using strrchr and strrchr_reverse.
<?
//strxchr(string haystack, string needle [, bool int leftinclusive [, bool int rightinclusive ]])
function strxchr($haystack, $needle, $l_inclusive = 0, $r_inclusive = 0){
if(strrpos($haystack, $needle)){
//Everything before last $needle in $haystack.
$left = substr($haystack, 0, strrpos($haystack, $needle) + $l_inclusive);
//Switch value of $r_inclusive from 0 to 1 and viceversa.
$r_inclusive = ($r_inclusive == 0) ? 1 : 0;
//Everything after last $needle in $haystack.
$right = substr(strrchr($haystack, $needle), $r_inclusive);
//Return $left and $right into an array.
$a = array($left, $right);
return $a;
}else{
return false;
}
}
//start test
$haystack = "unknown.txt.log.......gif.....jpeg";
$needle = ".";
$l_inclusive = 1; //1 for inclusive mode, 0 for NOT inclusive mode
$r_inclusive = 1; //1 for inclusive mode, 0 for NOT inclusive mode
$a = strxchr($haystack, $needle, $l_inclusive, $r_inclusive);
if($a){echo "Left: <strong>" . $a[0] . "</strong><br /> Right:
<strong>" . $a[1] . "</strong>";}else{echo "Failed!";}
//end test
?>
Thanks to all.
Repley
----
Server IP: 80.241.173.254
Probable Submitter: 84.222.146.228
----
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/66306
Del: integrated -- http://master.php.net/note/delete/66306/integrated
Del: useless -- http://master.php.net/note/delete/66306/useless
Del: bad code -- http://master.php.net/note/delete/66306/bad+code
Del: spam -- http://master.php.net/note/delete/66306/spam
Del: non-english -- http://master.php.net/note/delete/66306/non-english
Del: in docs -- http://master.php.net/note/delete/66306/in+docs
Del: other reasons-- http://master.php.net/note/delete/66306
Reject -- http://master.php.net/note/reject/66306
Search -- http://master.php.net/manage/user-notes.php