Posted By

kirik on 11/11/09


Tagged

get file extension


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

BrianCoyDesign


Get file extension


 / Published in: PHP
 

This function works correct with files with no extension.

  1. function getExtension($filename)
  2. {
  3. return ('.' . ($ext = pathinfo($filename, PATHINFO_EXTENSION)) == $filename) ? null : $ext;
  4. }
  5.  
  6. // Example:
  7. var_dump(getExtension('.htaccess'), getExtension('image.jpg'));
  8. // Result:
  9. // NULL
  10. // string(3) "jpg"

Report this snippet  

You need to login to post a comment.