Created
November 25, 2017 21:44
-
-
Save dejurin/3ac5de4bb86dbce14bb850520fc253a1 to your computer and use it in GitHub Desktop.
Get extension of file if you have only string (filename.ext)
This file contains 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
function get_file_extension($filename) | |
{ | |
/* | |
* "." for extension should be available and not be the first character | |
* so position should not be false or 0. | |
*/ | |
$last_dot_pos = strrpos($filename, '.'); | |
if ( !$last_dot_pos ) return false; | |
return substr($filename, $last_dot_pos + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment