note 68563 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Wed, 02 Aug 2006 13:08:51 +0000 |
| Subject: | note 68563 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115482@lists.php.net to get a copy of this message | ||
Note Submitter: Sigmus
Reason: useless
----
A simple way to extract a file extension using explode:
<?php
function get_ext($file) {
$parts = explode(".",$file);
// If there is no extension function returns false
if (count($parts) <= 1) {
return false;
}
// Returns the extension if there is one
else {
return strtolower($parts[count($parts)-1]);
}
}
?>
Note that this function allows the file to have extra dots before the "final extension".
Something like "my.file.doc" would have ".doc" as a result. Extensions are
converted to lowercase using strtolower().