lychee/php/helpers/getExtension.php

20 lines
478 B
PHP
Raw 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-17 08:28:31 +00:00
// If $filename is an URI, get only the path component
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-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
}
?>