note 51818 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Mon, 25 Sep 2006 08:10:12 +0000 |
| Subject: | note 51818 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117591@lists.php.net to get a copy of this message | ||
Note Submitter: Bob
----
I only have access to a really old ver. of php so when I had to come up with a way to grab a
filename w/o the suffix (.whatever) i came up with this:
function remSuffix ($inputString) {
$origString = $inputString;
$inputString = explode(".",strrev($inputString),2);
if (strlen($inputString[1])<>0) {
return strrev($inputString[1]);
} else
return $origString;
}
takes string, if it has a '.', it returns everything in front of the last occurence of
'.'
so :
echo remSuffix("some.file.txt");
will return
some.file
echo remSuffix("somefile.txt");
will return
somefile
if there is no '.' present, then the entire string is returned.
echo remSuffix("somefiletxt");
will return
somefiletxt
from the docs, it seems that in php5 that this can be accomplished by using a -ve limiter so use
that instead of you have it!