Return to Snippet

Revision: 62456
at February 24, 2013 20:16 by apphp-snippets


Initial Code
<?php
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;
}
?>

Initial URL
http://www.apphp.com/index.php?snippet=php-get-file-extension

Initial Description
This code allows to pass filename in the $file_name variable and function will return file extension only.

Initial Title
Get File Extension in PHP

Initial Tags
php, file, extension

Initial Language
PHP