note 51818 added to function.explode
| From: | Bob at osu1 dot php dot net | Date: | Tue, 12 Apr 2005 07:07:12 +0000 |
| Subject: | note 51818 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87879@lists.php.net to get a copy of this message | ||
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!
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51818
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51818&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51818&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51818&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51818&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51818&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51818&report=yes
Search -- http://master.php.net/manage/user-notes.php