Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
Created November 4, 2012 20:06
Show Gist options
  • Select an option

  • Save apphp-snippets/4013426 to your computer and use it in GitHub Desktop.

Select an option

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.
<?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