Back to File class

Method getExt

public static string
getExt
(mixed $file)
Gets the extension of a file name
Parameters
  • string $file The file name
Returns
  • string The file extension
Since
  • 1.7.0
Class: File
Project: Joomla

Method getExt - Source code

/**
 * Gets the extension of a file name
 *
 * @param   string  $file  The file name
 *
 * @return  string  The file extension
 *
 * @since   1.7.0
 */
public static function getExt($file)
{
    // String manipulation should be faster than pathinfo() on newer PHP versions.
    $dot = strrpos($file, '.');
    if ($dot === false) {
        return '';
    }
    $ext = substr($file, $dot + 1);
    // Extension cannot contain slashes.
    if (strpos($ext, '/') !== false || DIRECTORY_SEPARATOR === '\\' && strpos($ext, '\\') !== false) {
        return '';
    }
    return $ext;
}