Created
November 4, 2012 20:06
-
-
Save apphp-snippets/4013426 to your computer and use it in GitHub Desktop.
This code allows to pass filename in the $file_name variable and function will return file extension only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Source: http://www.apphp.com/index.php?snippet=php-get-file-extension */ | |
| function get_file_extension($file_name) | |
| { | |
| /* may contain multiple dots */ | |
| $string_parts = explode('.', $file_name); | |
| $extension = $string_parts[count($string_parts) - 1]; | |
| $extension = strtolower($extension); | |
| return $extension; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment