getExtension.php 412 B

123456789101112131415161718
  1. <?php
  2. # Returns the extension of the filename (path or URI) or an empty string
  3. function getExtension($filename, $isURI = false) {
  4. # If $filename is an URI, get only the path component
  5. if ($isURI)
  6. $filename = parse_url($filename, PHP_URL_PATH);
  7. $extension = pathinfo($filename, PATHINFO_EXTENSION);
  8. if (!empty($extension))
  9. $extension = '.' . $extension;
  10. return $extension;
  11. }
  12. ?>