lychee/php/helpers/getExtension.php

24 lines
599 B
PHP
Raw Permalink Normal View History

<?php
2016-03-17 08:28:31 +00:00
/**
* Returns the extension of the filename (path or URI) or an empty string.
* @return string Extension of the filename starting with a dot.
*/
2016-03-16 16:07:22 +00:00
function getExtension($filename, $isURI = false) {
2016-03-18 21:09:54 +00:00
// If $filename is an URI, get only the path component
2016-03-17 08:28:31 +00:00
if ($isURI===true) $filename = parse_url($filename, PHP_URL_PATH);
2016-03-16 16:07:22 +00:00
$extension = pathinfo($filename, PATHINFO_EXTENSION);
2016-03-18 21:09:54 +00:00
// Special cases
// https://github.com/electerious/Lychee/issues/482
list($extension) = explode(':', $extension, 2);
2016-03-17 18:21:59 +00:00
2016-03-17 08:28:31 +00:00
if (empty($extension)===false) $extension = '.' . $extension;
2016-03-16 16:07:22 +00:00
return $extension;
2016-03-17 08:28:31 +00:00
}
?>