FyrePath is a free, open-source path library for PHP.
Using Composer
composer require fyre/path
In PHP:
use Fyre\Utility\Path;
Base Name
Get the base name from a file path.
$path
is a string representing the file path.
$baseName = Path::baseName($path);
Dir Name
Get the directory name from a file path.
$path
is a string representing the file path.
$dirName = Path::dirName($path);
Extension
Get the file extension from a file path.
$path
is a string representing the file path.
$extension = Path::extension($path);
File Name
Get the file name from a file path.
$path
is a string representing the file path.
$fileName = Path::fileName($path);
Format
Format path info as a file path.
$pathInfo
is an array containing the path info.
$path = Path::format($pathInfo);
Is Absolute
Determine whether a file path is absolute.
$path
is a string representing the file path.
$isAbsolute = Path::isAbsolute($path);
Join
Join path segments.
All arguments supplied will be joined.
$path = Path::join(...$paths);
Normalize
Normalize a file path.
$path
is a string representing the file path.
$normalized = Path::normalize($path);
Parse
Parse a file path.
$path
is a string representing the file path.
$pathInfo = Path::parse($path);
Resolve
Resolve a file path from path segments.
All arguments supplied will be resolved.
$path = Path::resolve(...$paths);