getExtension.php 478 B

1234567891011121314151617181920
  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. if (empty($extension)===false) $extension = '.' . $extension;
  11. return $extension;
  12. }
  13. ?>