Skip to content

Instantly share code, notes, and snippets.

@dejurin
Created November 25, 2017 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dejurin/3ac5de4bb86dbce14bb850520fc253a1 to your computer and use it in GitHub Desktop.
Save dejurin/3ac5de4bb86dbce14bb850520fc253a1 to your computer and use it in GitHub Desktop.
Get extension of file if you have only string (filename.ext)
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