note 114978 added to function.end
| From: | ivijan dot stefan at gmail dot com | Date: | Thu, 08 May 2014 16:47:21 +0000 |
| Subject: | note 114978 added to function.end | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199486@lists.php.net to get a copy of this message | ||
I found that the function end() is the best for finding extensions on file name. This function
cleans backslashes and takes the extension of a file.
<?php
private function extension($str){
$str=implode("",explode("\\",$str));
$str=explode(".",$str);
$str=strtolower(end($str));
return $str;
}
// EXAMPLE:
$file='name-Of_soMe.File.txt';
echo extension($file); // txt
?>
Very simple.
----
Server IP: 72.52.91.14
Probable Submitter: 95.85.174.65
----
Manual Page -- http://php.net/manual/en/function.end.php
Edit -- https://master.php.net/note/edit/114978
Del: integrated -- https://master.php.net/note/delete/114978/integrated
Del: useless -- https://master.php.net/note/delete/114978/useless
Del: bad code -- https://master.php.net/note/delete/114978/bad+code
Del: spam -- https://master.php.net/note/delete/114978/spam
Del: non-english -- https://master.php.net/note/delete/114978/non-english
Del: in docs -- https://master.php.net/note/delete/114978/in+docs
Del: other reasons-- https://master.php.net/note/delete/114978
Reject -- https://master.php.net/note/reject/114978
Search -- https://master.php.net/manage/user-notes.php