Posted By

apphp-snippets on 02/24/13


Tagged

php file extension


Versions (?)

Get File Extension in PHP


 / Published in: PHP
 

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

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

  1. <?php
  2. function get_file_extension($file_name)
  3. {
  4. /* may contain multiple dots */
  5. $string_parts = explode('.', $file_name);
  6. $extension = $string_parts[count($string_parts) - 1];
  7. $extension = strtolower($extension);
  8. return $extension;
  9. }
  10. ?>

Report this snippet  

You need to login to post a comment.