Webmozart\PathUtil\Path::getExtension PHP Method

getExtension() public static method

Returns the extension from a file path.
Since: 1.1 Added method.
Since: 2.0 Method now fails if $path is not a string.
public static getExtension ( string $path, boolean $forceLowerCase = false ) : string
$path string The path string.
$forceLowerCase boolean Forces the extension to be lower-case (requires mbstring extension for correct multi-byte character handling in extension).
return string The extension of the file path (without leading dot).
    public static function getExtension($path, $forceLowerCase = false)
    {
        if ('' === $path) {
            return '';
        }
        Assert::string($path, 'The path must be a string. Got: %s');
        $extension = pathinfo($path, PATHINFO_EXTENSION);
        if ($forceLowerCase) {
            $extension = self::toLower($extension);
        }
        return $extension;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     $ext = Path::getExtension($path, true);
     if ('' == trim($ext)) {
         return null;
     }
     return isset($this->mimes[$ext]) ? $this->mimes[$ext] : null;
 }
All Usage Examples Of Webmozart\PathUtil\Path::getExtension