lychee/php/helpers/getExtension.php

18 lines
412 B
PHP
Raw Normal View History

<?php
2016-03-16 16:07:22 +00:00
# Returns the extension of the filename (path or URI) or an empty string
function getExtension($filename, $isURI = false) {
2016-03-16 16:07:22 +00:00
# If $filename is an URI, get only the path component
if ($isURI)
$filename = parse_url($filename, PHP_URL_PATH);
2016-03-16 16:07:22 +00:00
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if (!empty($extension))
$extension = '.' . $extension;
2016-03-16 16:07:22 +00:00
return $extension;
}
?>