getExtension.php 583 B

1234567891011121314151617181920212223
  1. <?php
  2. /**
  3. * Returns the extension of the filename (path or URI) or an empty string.
  4. * @return string Extension of the filename starting with a dot.
  5. */
  6. function getExtension($filename, $isURI = false) {
  7. # If $filename is an URI, get only the path component
  8. if ($isURI===true) $filename = parse_url($filename, PHP_URL_PATH);
  9. $extension = pathinfo($filename, PATHINFO_EXTENSION);
  10. # Special cases
  11. if (strpos($extension, ':')!==false) list($extension, ) = explode(':', $extension, 2);
  12. if (empty($extension)===false) $extension = '.' . $extension;
  13. return $extension;
  14. }
  15. ?>