Returns file extension

@param string $fileName    File name
@param bool   $asLowerCase (optional) if true extension is returned as lowercase string
@return string
977176
public static function getFileExtension($fileName, $asLowerCase = false)
    {
        $extension = '';
        $matches = [];

        if (preg_match('|(.+)\.(.+)|', $fileName, $matches)) {
            $extension = end($matches);
        }

        if ($asLowerCase) {
            return strtolower($extension);
        }

        return $extension;
    }
723933
public function normalize($fileName, $suffix = 0)
    {
        if ($this->casePreservation === self::LOWER_CASE) {
            $fileName = strtolower($fileName);
        }

        $ret = preg_replace('/[^\w.]+/', '-', $fileName);
        $ret = preg_replace('/-+/', '-', $ret);

        if ($suffix !== 0) {
            $ext = (string)pathinfo($ret, PATHINFO_EXTENSION);
            $fn = (string)pathinfo($ret, PATHINFO_FILENAME);
            $ret = sprintf('%s-%d.%s', trim($fn, '.'), $suffix, $ext);
        }

        return $ret;
    }
648218
public function getFilenameWithExtension() {
		if ($this->extension === null) {
			return $this->filename;
		}
		else {
			return $this->filename . '.' . $this->extension;
		}
	}
461621
protected function fileMatchesMoreSpecificExtension(string $filename, string $extension) : bool
    {
      return array_reduce($this->extensions, function ($match, $compare) use ($filename, $extension) {
        if ($match || $compare === $extension || strlen($compare) < strlen($extension)) {
          return $match;
        }

        return $filename === basename($filename, ".{$compare}").".{$compare}";
      }, false);
    }
445875
public function getExtensionByFileName($filepath)
    {
        $path = pathinfo($filepath);

        // check if the file has the extenison and we need
        // to lower down the extension (caused unknown extension for uppercased extension)
        if (isset($path['extension'])) {
            return strtolower($path['extension']);
        } else if (is_string($this->getMime())) {
            return str_replace("image/", "", $this->getMime());
        } else if ($this->format != "") {
            return $this->format;
        } else {
            // fallback to enable save image on empty extension. ImageMagick has no problem with this.
            return "jpg";
        }
    }
292912
private function _getExtension($file = null)
	{
		if (!is_null($file))
		{
			$dot = strrpos($file, '.') + 1;

			return strtolower(substr($file, $dot));
		}

		return '##INVALID_FILE##';
	}
148063
public static function normalizeFileName($fileName, $withExtension = true)
    {
        // Remove filename's extension.
        $fileName = basename($fileName);
        $extension = substr($fileName, strrpos($fileName, ".") + 1, strlen($fileName) - strrpos($fileName, "."));
        $fileName = substr($fileName, 0, strrpos($fileName, "."));

        // Convert to lowercase.
        $fileName = strtolower($fileName);

        // Convert characters to the range a-z_-
        $fileName = strtr($fileName, "√°√©√≠√≥√∫√†√®√¨√≤√π√§√´√Ø√∂√º√¢√™√Æ√¥√ª√±√ß", "aeiouaeiouaeiouaeiounc");
        $fileName = preg_replace("/([\W]+)/", "_", $fileName);

        if ($withExtension) {
            $fileName .= '.' . $extension;
        }

        return $fileName;
    }
408152
protected function replaceExtension($filename, $ext)
    {
        $ext = str_replace('.', '', $ext);
        $filename = $this->removeExtension($filename);

        return $filename.'.'.$ext;
    }
758996
public static function getExtension($filename)
    {
        Deprecated::method(3.0, 'Use pathinfo() instead.');

        $pos = strrpos($filename, '.');
        if ($pos === false) {
            return '';
        }
        $ext = substr($filename, $pos + 1);

        return $ext;
    }
1123944
public function getFilename(string $fileStartLine): string
    {
        // In case of parse error fall back to returning the line minus the plus or minus symbols.
        if (!preg_match(static::FILENAME_REGEX, $fileStartLine, $matches)) {
            return substr($fileStartLine, 4);
        }

        return $matches['filename'];
    }
852839
public static String getSafeExtension(final String filename) {
        // extension does not include period (.)
        final String extension = FilenameUtils.getExtension(filename);
        return isSafeExtension(extension) ? "." + extension : StringUtils.EMPTY;
    }
120118
public static function getExtensions(array $mimesTypes, $asUpperCase = false)
    {
        if (empty($mimesTypes)) {
            return [];
        }

        $extensions = [];

        foreach ($mimesTypes as $mimeType) {
            $extension = self::getExtension($mimeType);

            /*
             * No extension for given mime type?
             * Nothing to do
             */
            if (empty($extension)) {
                continue;
            }

            if ($asUpperCase) {
                if (is_array($extension)) {
                    array_walk($extension, function (&$value) {
                        $value = strtoupper($value);
                    });
                } else {
                    $extension = strtoupper($extension);
                }
            }

            $extensions[$mimeType] = $extension;
        }

        return $extensions;
    }
1309987
public function getNamesWithDifferentExtension(string $fileName)
    {
        if (! file_exists($this->basePath)) {
            return [];
        }

        $extension = pathinfo($fileName, PATHINFO_EXTENSION);

        $baseName = substr($fileName, 0, strlen($fileName) - strlen($extension) - 1);

        $allNames = scandir($this->basePath);

        $namesWithDifferentExtension = array_filter($allNames, function ($existingName) use ($baseName, $extension) {
            $existingExtension = pathinfo($existingName, PATHINFO_EXTENSION);

            $existingBaseName = substr($existingName, 0, strlen($existingName) - strlen($existingExtension) - 1);

            return $existingBaseName === $baseName && $existingExtension !== $extension;
        });

        return array_values($namesWithDifferentExtension);
    }
1159485
public static String getExtension(String fileName){
        int dot = fileName.lastIndexOf('.');
        return dot==-1 ? null : fileName.substring(dot+1);
    }
1174401
public static function removeExtension($filename)
    {
        if (false === strrpos($filename, '.')) {
            return $filename;
        }

        return substr($filename, 0, strrpos($filename, '.'));
    }
45652
public static function getFileNameWithoutExtension($fileName)
    {
        $matches = [];

        if (is_string($fileName) && (bool)preg_match('|(.+)\.(.+)|', $fileName, $matches)) {
            return $matches[1];
        }

        return '';
    }
1055100
public static function fromFile(string $filename, bool $allowGuessByExtension): MediaType
    {
        $result = 'application/octet-stream';

        if (!@is_file($filename) || !@is_readable($filename)) {
            return new self($result);
        }

        $result = self::guessFromFinfo($filename);
        if (self::isFallback($result)) {
            $result = self::guessFromFileCommand($filename);
        }

        if ($allowGuessByExtension && self::isFallback($result)) {
            $extension = pathinfo($filename, PATHINFO_EXTENSION);
            if (self::isKnownExtension($extension)) {
                return self::fromExtension($extension);
            }
        }

        $result = str_replace(['charset=binary', 'charset=us-ascii'], ['', ''], strtolower($result));
        $result = rtrim($result, '; ');

        return new self($result);
    }