getExtension.php 599 B

123456789101112131415161718192021222324
  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. // https://github.com/electerious/Lychee/issues/482
  12. list($extension) = explode(':', $extension, 2);
  13. if (empty($extension)===false) $extension = '.' . $extension;
  14. return $extension;
  15. }
  16. ?>