Get File Extension in PHP


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.