PHPackages                             lazervel/path - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. lazervel/path

ActiveLibrary[File &amp; Storage](/categories/file-storage)

lazervel/path
=============

Help with handling or manipulating file and directory path.

v1.0.0(6mo ago)3127↓100%141MITPHPPHP ^7.2 || ^8.0CI failing

Since Oct 31Pushed 6mo ago14 watchersCompare

[ Source](https://github.com/lazervel/path)[ Packagist](https://packagist.org/packages/lazervel/path)[ Docs](https://github.com/lazervel)[ Fund](https://github.com/indianmodassir)[ RSS](/packages/lazervel-path/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

PHP Path [![verified](https://raw.githubusercontent.com/lazervel/assets/main/icons/verified.png)](https://raw.githubusercontent.com/lazervel/assets/main/icons/verified.png)
============================================================================================================================================================================

[](#php-path-)

PHP Path Help with handling or manipulating file and directory path.

[![Banner](https://raw.githubusercontent.com/lazervel/assets/main/banners/path.png)](https://raw.githubusercontent.com/lazervel/assets/main/banners/path.png)

[![](https://camo.githubusercontent.com/a14ab1cda443102b95b1c80a8c6a37c1adca26e3b530108cb1288d248598b223/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417574686f722d496e6469616e2532304d6f6461737369722d2532333434636331313f7374796c653d666c61742d737175617265)](https://github.com/indianmodassir)[![](https://camo.githubusercontent.com/f86ae1e0fd8345bbac8f1bcddf5772044a3421256d94c08f7be9353078a562f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c617a657276656c2f706174683f7374796c653d666c61742d737175617265)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/259b8bd62b5c236df0f841e10c9b44ee310da217678d5fc757fee030ff11a258/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c617a657276656c2f706174682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lazervel/path)[![](https://camo.githubusercontent.com/a74d3a4608a8acccc29faf1c712addd02d02c4496b2a20e7b34d0adacb36e6bb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c617a657276656c2f706174683f7374796c653d666c61742d737175617265)](https://github.com/lazervel/path/stargazers)[![Latest Version](https://camo.githubusercontent.com/61438525fe98b69fda4094705e2dc38f06ea57ccf92729d602004ed52f965c5f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6c617a657276656c2f706174682e7376673f7374796c653d666c61742d737175617265)](https://github.com/lazervel/path/releases)[![Contributors](https://camo.githubusercontent.com/27261fe8ca233abdaaca2b64d5afd40580810bfb730baa51c709521ffd4e58d4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6c617a657276656c2f706174683f7374796c653d666c61742d737175617265)](https://github.com/lazervel/path/graphs/contributors)[![Repository Size](https://camo.githubusercontent.com/3667d9cbd98fff60fd83e3d8e0540052eb32462d326d32e40d08b7b6e102aecd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f6c617a657276656c2f706174683f7374796c653d666c61742d737175617265)](/)

Composer Installation
---------------------

[](#composer-installation)

Installation is super-easy via [Composer](https://getcomposer.org)

```
composer require lazervel/path
```

or add it by hand to your `composer.json` file.

```
use Lazervel\Path\Path;
require 'vendor/autoload.php';
```

The Features of PHP Path
------------------------

[](#the-features-of-php-path)

- [Path::basename($path\[, $suffix\])](#pathbasenamepath-suffix)
- [Path::canonicalize($path)](#pathcanonicalizepath)
- [Path::changeExt($path, $newExt)](#pathchangeextpath-newext)
- [Path::combine($paths, $names)](#pathcombinepaths-names)
- [Path::checkLength($path)](#pathchecklengthpath)
- [Path::delimiter](#pathdelimiter)
- [Path::dirname($path\[, $suffix, $levels\])](#pathdirnamepath-suffix-levels)
- [Path::extname($path)](#pathextnamepath)
- [Path::filename($path)](#pathfilenamepath)
- [Path::format($pathObject)](#pathformatpathobject)
- [Path::getcwd()](#pathgetcwd)
- [Path::hasExt($path)](#pathhasextpath)
- [Path::info()](#pathinfo)
- [Path::isAbsolute($path)](#pathisabsolutepath)
- [Path::isLocal($path)](#pathislocalpath)
- [Path::isURIPath($path)](#pathisuripathpath)
- [Path::join(\[...$paths\])](#pathjoinpaths)
- Path::localBase($paths)
- [Path::normalize($path)](#pathnormalizepath)
- [Path::optimize($path)](#pathoptimizepath)
- [Path::parse($path)](#pathparsepath)
- [Path::pathname($path)](#pathpathnamepath)
- [Path::pathToURL($path, $origin\[, ?$query, ?$hash\])](#pathpathtourlpath-origin-query-hash)
- [Path::posix](#pathposix)
- [Path::relative($from, $to)](#pathrelativefrom-to)
- [Path::removeExt($path)](#pathremoveextpath)
- [Path::resolve(...$paths)](#pathresolvepath)
- [Path::rootname($path)](#pathrootnamepath)
- [Path::sep](#pathsep)
- [Path::tmp($path)](#pathtmppath)
- [Path::toNamespacedPath($path)](#pathtonamespacedpathpath)
- [Path::UrlToPath($url)](#pathurltopathurl)
- [Path::win32](#pathwin32)

Path::basename($path\[, $suffix\])
----------------------------------

[](#pathbasenamepath-suffix)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- `$suffix` [string](https://www.php.net/manual/en/language.types.string) An optional suffix to remove
- Return: [string](https://www.php.net/manual/en/language.types.string)

The `Path::basename()` method returns the last portion of a path, similar to the Unix basename command. Trailing `directory separators` are ignored.

For example, on POSIX:

```
Path::basename('C:\\xampp\\htdocs\\example.html');
// Returns: 'example.html'

Path::basename('C:\\xampp\\htdocs\\example.html', '.html');
// Returns: 'example'
```

On Windows:

```
Path::basename('/home/local/user/example.html');
// Returns: 'example.html'

Path::basename('/home/local/user/example.html', '.html');
// Returns: 'example'
```

Path::canonicalize($path)
-------------------------

[](#pathcanonicalizepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

canonicalize function converts a given path into its canonical (absolute and standardized) form. It resolves relative paths, symbolic links, and eliminates redundant or unnecessary components like '.' and '..' to return a clean and absolute version of the path.

For example, on POSIX:

```
Path::canonicalize('C:\\XamPP\\HtDocS\\DatA\\comPoseR.jSon');
// Returns: 'C:\\xampp\\htdocs\\data\\composer.json'
```

On Windows:

```
Path::canonicalize('/path/composer.json');
// Returns: 'G:\\path\\composer.json'
```

Path::changeExt($path, $newExt)
-------------------------------

[](#pathchangeextpath-newext)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- `$newExt` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Returns a path string with changed initial extension to replaced new extension.
If path extension and givent new extension are same then changeExt will be not modify and return path with initial extension.

```
Path::changeExt('/foo/bar/baz/asdf/quux.html', '.php');
// Returns: '/foo/bar/baz/asdf/quux.php'

Path::changeExt('/foo/bar/baz/asdf/vector.gif', 'svg');
// Returns: '/foo/bar/baz/asdf/vector.svg'
```

Path::combine($paths, $names)
-----------------------------

[](#pathcombinepaths-names)

**Parameters:**

- `$paths` [array](https://www.php.net/manual/en/language.types.array)
- `$names` [array](https://www.php.net/manual/en/language.types.array)
- Return: [array](https://www.php.net/manual/en/language.types.array)

Creates an array by using one array for paths and another for its names. And creates multiple files combined with paths from to file names.

For example, on POSIX:

```
Path::combine(['/xampp/htdocs'], ['example.html', 'foo.txt']);
// Returns: ['/xampp/htdocs/example.html', '/xampp/htdocs/foo.txt']

Path::combine(['/xampp/htdocs'], ['example.html']);
// Returns: ['/xampp/htdocs/example.html']

Path::combine(['/xampp/htdocs', '/path'], ['example.html']);
// Returns: ['/xampp/htdocs/example.html', '/path/example.html']

Path::combine(['/xampp/htdocs', '/path'], ['example.html', 'foot.txt', '.env']);
// Returns: ['/xampp/htdocs/example.html', '/xampp/htdocs/foot.txt', '/xampp/htdocs/.env', '\path\example.html', '\path\foot.txt', '\path\.env']
```

On Windows:

```
Path::combine(['C:\\xampp\\htdocs'], ['example.html', 'foo.txt']);
// Returns: ['C:\\xampp\\htdocs\\example.html', 'C:\\xampp\\htdocs\\foo.txt']

Path::combine(['C:\\xampp\\htdocs'], ['example.html']);
// Returns: ['C:\\xampp\\htdocs\\example.html']

Path::combine(['C:\\xampp\\htdocs', '\\path'], ['example.html']);
// Returns: ['C:\\xampp\\htdocs\\example.html', '\\path\\example.html']

Path::combine(['C:\\xampp\\htdocs', '\\path'], ['example.html', 'foot.txt', '.env']);
// Returns: ['C:\\xampp\\htdocs\\example.html', 'C:\\xampp\\htdocs\\foot.txt', 'C:\\xampp\\htdocs\\.env', '\\path\\example.html', '\\path\\foot.txt', '\\path\\.env']
```

Path::checkLength($path)
------------------------

[](#pathchecklengthpath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [void](https://www.php.net/manual/en/language.types.void)

Check a valid path length and report exception.

```
// Check maximum path length on your system use \PHP_MAXPATHLEN constant.
Path::checkLength('your-path');

// Returns: if given path of length are valid so return (void) otherwise throwing RTException Error.
// PHP Fatal error:  Uncaught Path\Exception\RTException: Invalid path because path length exceeds [2048] characters.
```

### Throwing Error

[](#throwing-error)

**Path\\Exception\\RTException: Invalid path because path length exceeds \[2048\] characters.**

Path::delimiter
---------------

[](#pathdelimiter)

Provides the platform-specific path delimiter:

- `;` for Windows
- `:` for POSIX

For example, on POSIX:

```
echo getenv('PATH');
// Prints: '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'

explode(Path::delimiter, getenv('PATH'));
// Returns: ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
```

On Windows:

```
echo getenv('PATH');
// Prints: 'C:\Windows\system32;C:\Windows;C:\Program Files\node\'

explode(Path::delimiter, getenv('PATH'));
// Returns ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
```

Path::dirname($path\[, $suffix, $levels\])
------------------------------------------

[](#pathdirnamepath-suffix-levels)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- `$suffix` [string](https://www.php.net/manual/en/language.types.string)
- `$levels` [int](https://www.php.net/manual/en/language.types.integer)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Get the directory name of a given path with optional suffix removal and level adjustment. This function returns the parent directory's path of the provided file or directory path. It also allows for an optional suffix to be removed from the base name and specifies how many levels up the directory to go.

For example, on POSIX:

```
Path::dirname('/foo/bar/baz/asdf/quux\\abcd\\xyz');
// Returns: '/foo/bar/baz/asdf'
```

On Windows:

```
Path::dirname('/foo/bar/baz/asdf/quux');
// Returns: '/foo/bar/baz/asdf'

Path::dirname('/foo/bar/baz/asdf/quux\\abcd\\xyz');
// Returns: '/foo/bar/baz/asdf/quux\abcd'
```

Path::extname($path)
--------------------

[](#pathextnamepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Returns extname method a path extension name from given path, Its used to get file extention.

```
Path::extname('C:\\xampp\\htdocs\\example.html');
// Returns: '.html'

Path::extname('index.coffee.md');
// Returns: '.md'

Path::extname('index.');
// Returns: '.'

Path::extname('index');
// Returns: ''

Path::extname('.index');
// Returns: '.index'

Path::extname('C:\\xampp\\htdocs\\example.md');
// Returns: '.md'
```

Path::filename($path)
---------------------

[](#pathfilenamepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Returns a filename without extention of given path.

```
Path::filename('/foo/bar/baz/asdf/quux.html');
// Returns: 'quux.html'

Path::filename('example.txt');

Path::filename('/');
// Returns: ''
// Returns: 'example.txt'

Path::filename('example');
// Returns: 'example'

Path::filename('C:\\path\\dir\\file.txt');
// Returns: 'file.txt'
```

Path::format($pathObject)
-------------------------

[](#pathformatpathobject)

**Parameters:**

- `$pathObject` [array](https://www.php.net/manual/en/language.types.array)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Returns a path string from an array-object - the opposite of parse(). format method are same work as `phpinfo` method But there install the extra property `root` property to getting current root \[dir\] of path

For example, on POSIX:

```
// If `dir`, `root` and `base` are provided,
// `${dir}${Path::sep}${base}`
// will be returned. `root` is ignored.
Path::format([
  'root' => '/ignored',
  'dir' => '/home/user/dir',
  'base' => 'file.txt',
]);
// Returns: '/home/user/dir/file.txt'

// `root` will be used if `dir` is not specified.
// If only `root` is provided or `dir` is equal to `root` then the
// platform separator will not be included. `ext` will be ignored.
Path::format([
  'root' => '/',
  'base' => 'file.txt',
  'ext' => 'ignored',
]);
// Returns: '/file.txt'

// `name` + `ext` will be used if `base` is not specified.
Path::format([
  'root' => '/',
  'name' => 'file',
  'ext' => '.txt',
]);
// Returns: '/file.txt'

// The dot will be added if it is not specified in `ext`.
Path::format([
  'root' => '/',
  'name' => 'file',
  'ext' => 'txt',
]);
// Returns: '/file.txt'
```

On Windows:

```
Path::format([
  'dir' => 'C:\\path\\dir',
  'base' => 'file.txt',
]);
// Returns: 'C:\\path\\dir\\file.txt'
```

Path::getcwd()
--------------

[](#pathgetcwd)

Retrieves the current working directory based on the operating system. This method returns the current working directory in a format appropriate for the platform. For `POSIX` systems, it returns a path like `/xampp/htdocs/`, while for Windows systems, it returns a path like `C:/xampp/htdocs/`.

For example, on POSIX:

```
// If the current working directory is /xampp/htdocs,
Path::getcwd(); // Returns: /xampp/htdocs
```

On Windows:

```
// If the current working directory is C:\\xampp\\htdocs,
// returns with drive LIKE (eg: C:,D:,F: etc.)
Path::getcwd(); // Returns: C:\\xampp\\htdocs
```

Path::hasExt($path)
-------------------

[](#pathhasextpath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [bool](https://www.php.net/manual/en/language.types.boolean)

hasExt method will check extension exists or not exists of given path and matcher Extensions, if Given extensions in matched path extension then return true, Otherwise return false.

```
Path::hasExt('/foo/bar/baz/asdf/vector.png', ['.gif', '.jpg', '.png']); // Returns: true
Path::hasExt('/foo/bar/baz/asdf/vector.gif', '.gif');                   // Returns: true
Path::hasExt('/foo/bar/baz/asdf/vector.gif', 'gif');                    // Returns: true
Path::hasExt('/foo/bar/baz/asdf/vector.gif', ['gif', 'jpeg', 'png']);   // Returns: true

Path::hasExt('/foo/bar/baz/asdf/vector.pdf', ['.gif', '.jpg', '.png']); // Returns: false
Path::hasExt('/foo/bar/baz/asdf/vector.gif', '.svg');                   // Returns: false
Path::hasExt('/foo/bar/baz/asdf/vector.gif', 'png');                    // Returns: false
Path::hasExt('/foo/bar/baz/asdf/vector.gif', ['svg', 'jpeg', 'png']);   // Returns: false
```

Path::info()
------------

[](#pathinfo)

Returns information about a file path.

For example, on POSIX:

```
Path::info('/home/local/user/example.html');
// Returns: stdClass Object (
//   [dirname] => /home/local/user
//   [basename] => example.html
//   [extension] => html
//   [filename] => example
//   [root] => /
// )
```

On Windows:

```
Path::info('C:\\xampp\\htdocs\\path\\Path.php');
// Returns: stdClass Object (
//   [dirname] => C:\xampp\htdocs\path
//   [basename] => Path.php
//   [extension] => php
//   [filename] => Path
//   [root] => C:\
// )
```

Path::isAbsolute($path)
-----------------------

[](#pathisabsolutepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [bool](https://www.php.net/manual/en/language.types.boolean)

Determines whether {path} is an absolute path. An absolute path will always resolve to the same location,regardless of the working directory.

For example, on POSIX:

```
Path::isAbsolute('/foo/bar'); // Returns: true
Path::isAbsolute('/baz/..');  // Returns: true
Path::isAbsolute('qux/');     // Returns: false
Path::isAbsolute('.');        // Returns: false
```

On Windows:

```
Path::isAbsolute('//server');    // Returns: true
Path::isAbsolute('\\\\server');  // Returns: true
Path::isAbsolute('C:/foo/..');   // Returns: true
Path::isAbsolute('C:\\foo\\..'); // Returns: true
Path::isAbsolute('bar\\baz');    // Returns: false
Path::isAbsolute('bar/baz');     // Returns: false
Path::isAbsolute('.');           // Returns: false
```

Path::isLocal($path)
--------------------

[](#pathislocalpath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [bool](https://www.php.net/manual/en/language.types.boolean)

isLocal function checks whether the provided path is local or not. It determines if the given path refers to a local file or directory.

```
Path::isLocal('C:Users\JohnDoe\Documents\file.txt');  // Returns: 'false'
Path::isLocal('//home/user/file.txt');                // Returns: 'false'
Path::isLocal('C:\Program Files\file//file.txt');     // Returns: 'false'
Path::isLocal('C:/Windows\\System32');                // Returns: 'false'
Path::isLocal('D:\\Data\report.pdf');                 // Returns: 'false'
Path::isLocal('C:\Users\JohnDoe\Documents\file.txt'); // Returns: 'true'
Path::isLocal('D:\Projects\Code\index.html');         // Returns: 'true'
Path::isLocal('/home/user/documents/report.pdf');     // Returns: 'true'
Path::isLocal('\\ServerName\SharedFolder\image.png'); // Returns: 'true'
Path::isLocal('E:\Music\Rock\song.mp3');              // Returns: 'true'
```

Path::isURIPath($path)
----------------------

[](#pathisuripathpath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [bool](https://www.php.net/manual/en/language.types.boolean)

Check if the given path is a valid network path. A valid network path starts with two backslashes `\\` or `//` followed by the server name, and can include subdirectories.

**Support:** working only Windows:

```
Path::isURIPath('//home/local/user/'); // Returns: true
Path::isURIPath('//home/local');       // Returns: true
Path::isURIPath('//home/local/');      // Returns: true
Path::isURIPath('/server/foo/');       // Returns: false
Path::isURIPath('D:/');                // Returns: false
Path::isURIPath('//home/');            // Returns: false
Path::isURIPath('C:/xampp/htdocs/');   // Returns: false
```

Path::join(\[...$paths\])
-------------------------

[](#pathjoinpaths)

**Parameters:**

- `...$paths` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Join all arguments together and normalize the resulting path.

```
Path::join('/foo', 'bar', 'baz/asdf', 'quux', '..');
// Returns: '/foo/bar/baz/asdf'

Path::join('foo', [], 'bar');
// Throws TypeError: Path\Path::join(): Argument #2 must be of type string, array given.
```

Path::localBase($paths)
-----------------------

[](#pathlocalbasepaths)

```
// Temporary Unavailable
```

Path::normalize($path)
----------------------

[](#pathnormalizepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Normalize a string path, reducing `..` and `.` parts. When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.

For example, on POSIX:

```
Path::normalize('/foo/bar//baz/asdf/quux/..');
// Returns: '/foo/bar/baz/asdf'
```

On Windows:

```
Path::normalize('C:\\temp\\\\foo\\bar\\..\\');
// Returns: 'C:\\temp\\foo\\'
```

Since Windows recognizes multiple path separators, both separators will be replaced by instances of the Windows preferred separator (`\`):

```
Path::win32::normalize('C:////temp\\\\/\\/\\/foo/bar');
// Returns: 'C:\\temp\\foo\\bar'
```

Path::optimize($path)
---------------------

[](#pathoptimizepath)

Optimize method working As Path::format() but this method in common different, This method will be convert backward slashes to forward slash and convert forward slash to backward slash depend on `window` and `posix`

Optimize reducing '..' and '.' parts. When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.

For example, on POSIX:

```
Path::optimize('C:////temp\\\\/\\/\\/foo/bar');
// Returns: C:/temp/foo/bar
```

On Windows:

```
Path::optimize('C:////temp\\\\/\\/\\/foo/bar');
// Returns: C:\\temp\\foo\\bar
```

Path::parse($path)
------------------

[](#pathparsepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [array](https://www.php.net/manual/en/language.types.array)&lt;[string](https://www.php.net/manual/en/language.types.string),[string](https://www.php.net/manual/en/language.types.string)&gt;

Returns an object from a path string - the opposite of `format()`.

For example, on POSIX:

```
Path::parse('/home/user/dir/file.txt');
// Returns:
// [
//   'root' => '/',
//   'dir' => '/home/user/dir',
//   'base' => 'file.txt',
//   'ext' => '.txt',
//   'name' => 'file'
// ]
```

```
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
"  /    home/user/dir / file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)

```

On Windows:

```
path.parse('C:\\path\\dir\\file.txt');
// Returns:
// [
//   'root' => 'C:\\',
//   'dir' => 'C:\\path\\dir',
//   'base' => 'file.txt',
//   'ext' => '.txt',
//   'name' => 'file'
// ]
```

```
┌─────────────────────┬────────────┐
│          dir        │    base    │
├──────┬              ├──────┬─────┤
│ root │              │ name │ ext │
" C:\      path\dir   \ file  .txt "
└──────┴──────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)

```

Path::pathname($path)
---------------------

[](#pathpathnamepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Get the path name of a given file or directory. This function returns the path name without any suffix or modification and without drive.

For example, on POSIX:

```
Path::pathname('//var/www/httpdocs/config/config.yml');
// Returns: '/var/www/httpdocs/config/config.yml'

Path::pathname('C:////temp\\\\/\\/\\/foo/bar');
// Returns: 'C:/temp\foo/bar'

Path::pathname('/');
// Returns: '/'

Path::pathname('/var/www/httpdocs/config/config.yml');
// Returns: '/var/www/httpdocs/config/config.yml'
```

On Windows:

```
// Handle Network Path, Here network path are '\\\\var\\www'
Path::pathname('\\\\var\\www\\httpdocs\\config\\config.yml');
// Returns: '\\httpdocs\\config\\config.yml'

Path::pathname('C:////temp\\\\/\\/\\/foo/bar');
// Returns: '\\temp\\foo\\bar'

Path::pathname('\\var\\www\\httpdocs\\config\\config.yml');
// Returns: '\\var\\www\\httpdocs\\config\\config.yml'

Path::pathname('\\\\var\\www\\');
// Returns: '\\'

Path::pathname('C:');
// Returns: ''

Path::pathname('C:\\');
// Returns: '\\'

Path::pathname('\\\\var\\www');
// Returns: ''

Path::pathname('G:var\\www\\httpdocs\\config\\config.yml');
// Returns: 'var\\www\\httpdocs\\config\\config.yml'
```

Since Windows recognizes multiple path separators, both separators will be replaced by instances of the Windows preferred separator (`\`):

Path::pathToURL($path, $origin\[, ?$query, ?$hash\])
----------------------------------------------------

[](#pathpathtourlpath-origin-query-hash)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- `$origin` [string](https://www.php.net/manual/en/language.types.string)
- `$query` [string](https://www.php.net/manual/en/language.types.string)
- `$hash` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

pathToURL - Convert path to url, Returns path to url combination with `(e.g., path, origin, ?query, ?hash)`.

**Notice:** Don't use syntax `Path::win32::pathToURL()` or `Path::posix::pathToURL()`, This a common bugs. but don't worry we fix this bugs to next expected version `[v10.2.0]`.

For example, on POSIX:

```
Path::pathToURL('server/auth/client', 'https://www.example.com', 'id=1');
// Returns: 'https://www.example.com/server/auth/client?id=1'

Path::pathToURL('server/auth/client', 'https://www.example.com');
// Returns: 'https://www.example.com/server/auth/client'

Path::pathToURL('server/auth/client', 'https://www.example.com', '?id=1', '#root');
// Returns: 'https://www.example.com/server/auth/client?id=1#root'

Path::pathToURL('server/auth/client', 'https://www.example.com', '?id=1', 'root');
// Returns: 'https://www.example.com/server/auth/client?id=1#root'
```

On Windows:

```
Path::pathToURL('G:\\server\\auth\\client', 'https://www.example.com', 'id=1');
// Returns: 'https://www.example.com/server/auth/client?id=1'

Path::pathToURL('G:\\server\\auth\\client', 'https://www.example.com');
// Returns: 'https://www.example.com/server/auth/client'

Path::pathToURL('G:\\server\\auth\\client', 'https://www.example.com', '?id=1', '#root');
// Returns: 'https://www.example.com/server/auth/client?id=1#root'

Path::pathToURL('G:\\server\\auth\\client', 'https://www.example.com', '?id=1', 'root');
// Returns: 'https://www.example.com/server/auth/client?id=1#root'
```

Path::posix
-----------

[](#pathposix)

The `Path::posix` property provides access to POSIX specific implementations of the `Path` methods.

The API is accessible via `Path\Path::posix` or `Path\Linux\Linux::class`.

Path::relative($from, $to)
--------------------------

[](#pathrelativefrom-to)

**Parameters:**

- `$from` [string](https://www.php.net/manual/en/language.types.string)
- `$to` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Solve the relative path from `from` to `to` based on the current working directory. At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.

For example, on POSIX:

```
Path::relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
// Returns: '../../impl/bbb'
```

On Windows:

```
Path::relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb');
// Returns: '..\\..\\impl\\bbb'
```

Path::removeExt($path)
----------------------

[](#pathremoveextpath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Returns a path string with removed path extension.

```
Path::removeExt('/var/www/web.php');
// Returns: '/var/www/web'

Path::removeExt('.env.local');
// Returns: '.env'

Path::removeExt('.html');
// Returns: '' bugs detected

Path::removeExt('file.txt');
// Returns 'file'

Path::removeExt('G:/path/.github');
// Returns: 'G:/path/' bugs detected
```

Path::resolve(...$path)
-----------------------

[](#pathresolvepath)

**Parameters:**

- `...$paths` [string](https://www.php.net/manual/en/language.types.string) A sequence of path segments.
- Return: [string](https://www.php.net/manual/en/language.types.string)

The right-most parameter is considered `to`. Other parameters are considered an array of `from`. Starting from leftmost `from` parameter, resolves `to` to an absolute path. If `to` isn't already absolute, `from` arguments are prepended in right to left order, until an absolute path is found. If after using all `from` paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory.

For example, on POSIX:

```
Path::resolve('/foo/bar', './baz');
// Returns: '/foo/bar/baz'

Path::resolve('/foo/bar', '/tmp/file/');
// Returns: '/tmp/file'

Path::resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
// If the current working directory is /home/myself/node,
// this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'
```

On Windows:

```
Path::resolve('/foo/bar', './baz');
// Returns: 'G:\\foo\\bar\\baz'

Path::resolve('/foo/bar', '/tmp/file/');
// Returns: 'G:\\tmp\\file'

Path::resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
// If the current working directory is C:\\xampp\\htdocs/,
// this returns 'C:\\xampp\\htdocs\\wwwroot\\static_files\\gif\\image.gif'
```

Path::rootname($path)
---------------------

[](#pathrootnamepath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Retrieves the root name of the path. This method extracts the root component of a given path, which can be useful for determining the base directory or starting point for further path manipulations.

For example, on POSIX:

```
Path::rootname('C:\\xampp\\htdocs\\');
// Returns: ''

Path::rootname('/var/ww/httpdocs');
// Returns: '/'

Path::rootname('C:\\');
// Returns: ''

Path::rootname('G:');
// Returns: ''

Path::rootname('//var/www/httpdocs');
// Returns: '/'
```

On Windows:

```
Path::rootname('C:\\xampp\\htdocs\\');
// Returns: 'C:\\'

Path::rootname('/var/ww/httpdocs');
// Returns: '\\'

Path::rootname('C:\\');
// Returns: 'C:\\'

Path::rootname('G:');
// Returns: 'G:'

Path::rootname('//var/www/httpdocs');
// Returns: '\\\\var\\www\\'
```

Path::sep
---------

[](#pathsep)

For example, on POSIX:

```
explode(Path::sep, 'foo/bar/baz');
// Returns: ['foo', 'bar', 'baz']
```

On Windows:

```
explode(Path::sep, 'foo\\bar\\baz');
// Returns: ['foo', 'bar', 'baz']
```

On Windows, both the forward slash (`/`) and backward slash (`\`) are accepted as path segment separators; however, the `Path` methods only add backward slashes (`\`).

Path::tmp($path)
----------------

[](#pathtmppath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

Returns tmp name, To make a tmp name with dirname of given path.

For example, on POSIX:

```
// Path::tmp suffix random tmp name in given path value.
Path::tmp('foot/bar/baz');
// Returns: 'foot/bar/.!!/.!HyZq'
// Returns: 'foot/bar/.!!/.!XTfs'
// Returns: 'foot/bar/.!!/.!C80D'
```

On Windows:

```
// Path::tmp suffix random tmp name in given path value.
Path::tmp('foot\\bar\\baz');
// Returns: 'foot\\bar\\.!!\\.!RBDZ'
// Returns: 'foot\\bar\\.!!\\.!NPia'
// Returns: 'foot\\bar\\.!!\\.!0Kbx'
```

Path::toNamespacedPath($path)
-----------------------------

[](#pathtonamespacedpathpath)

**Parameters:**

- `$path` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

On `Windows` systems only, returns an equivalent namespace-prefixed path for the given path. If path is not a string, path will be returned without modifications. This method is meaningful only on Windows system. On `POSIX` systems, the method is non-operational and always returns path without modifications.

```
Path::toNamespacedPath('\\foo\\bar/baz\\asdfquux\\abcd\\xyz');
// Returns: '\\\\?\\G:\\foo\\bar\\baz\\asdfquux\\abcd\\xyz'

Path::toNamespacedPath('//foo\\bar/baz\\asdfquux\\abcd\\xyz');
// Returns: '\\\\?\\UNC\\foo\\bar\\baz\\asdfquux\\abcd\\xyz'
```

Path::UrlToPath($url)
---------------------

[](#pathurltopathurl)

**Parameters:**

- `$url` [string](https://www.php.net/manual/en/language.types.string)
- Return: [string](https://www.php.net/manual/en/language.types.string)

To convert url `https://example.com/home/parent/current/path` to `/home/parent/current/path`.

For example, on POSIX:

```
Path::UrlToPath('https://www.example.com/server/auth/client?id=1');
// Returns: '/server/auth/client'

Path::UrlToPath('https://www.example.com/server/auth/client');
// Returns: '/server/auth/client'

Path::UrlToPath('https://www.example.com/server/auth/client?id=1#root');
// Returns: '/server/auth/client'
```

On Windows:

```
Path::UrlToPath('https://www.example.com/server/auth/client?id=1');
// Returns: 'G:\\server\\auth\\client'

Path::UrlToPath('https://www.example.com/server/auth/client');
// Returns: 'G:\\server\\auth\\client'

Path::UrlToPath('https://www.example.com/server/auth/client?id=1#root');
// Returns: 'G:\\server\\auth\\client'
```

Path::win32
-----------

[](#pathwin32)

The `Path::win32` property provides access to Windows specific implementations of the `Path` methods.

The API is accessible via `Path\Path::win32` or `Path\Win32\Win32::class`.

Resources
---------

[](#resources)

- [Report issue](https://github.com/lazervel/path/issues) and [send Pull Request](https://github.com/lazervel/path/pulls) in the [main Lazervel repository](https://github.com/lazervel/path)

###  Health Score

40

—

FairBetter than 87% of packages

Maintenance72

Regular maintenance activity

Popularity22

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 53.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

189d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f450cf935f9bfadca6a1b355dff44fc62b535d389c62197422ecb858d7b04423?d=identicon)[indianmodassir](/maintainers/indianmodassir)

---

Top Contributors

[![indianmodassir](https://avatars.githubusercontent.com/u/152081666?v=4)](https://github.com/indianmodassir "indianmodassir (86 commits)")[![shahzada967](https://avatars.githubusercontent.com/u/226899880?v=4)](https://github.com/shahzada967 "shahzada967 (59 commits)")[![shahzadiafsu](https://avatars.githubusercontent.com/u/182284120?v=4)](https://github.com/shahzadiafsu "shahzadiafsu (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![modassirdev](https://avatars.githubusercontent.com/u/186417509?v=4)](https://github.com/modassirdev "modassirdev (1 commits)")[![ngdadnf](https://avatars.githubusercontent.com/u/186187994?v=4)](https://github.com/ngdadnf "ngdadnf (1 commits)")[![phpexp](https://avatars.githubusercontent.com/u/186431947?v=4)](https://github.com/phpexp "phpexp (1 commits)")[![promodassir](https://avatars.githubusercontent.com/u/121736316?v=4)](https://github.com/promodassir "promodassir (1 commits)")[![shahilsx](https://avatars.githubusercontent.com/u/187042373?v=4)](https://github.com/shahilsx "shahilsx (1 commits)")[![authmodassir](https://avatars.githubusercontent.com/u/186814361?v=4)](https://github.com/authmodassir "authmodassir (1 commits)")[![sidraham](https://avatars.githubusercontent.com/u/185451793?v=4)](https://github.com/sidraham "sidraham (1 commits)")[![codingwallah57](https://avatars.githubusercontent.com/u/186148228?v=4)](https://github.com/codingwallah57 "codingwallah57 (1 commits)")[![itzjuli](https://avatars.githubusercontent.com/u/186119370?v=4)](https://github.com/itzjuli "itzjuli (1 commits)")[![johnadam57](https://avatars.githubusercontent.com/u/186262548?v=4)](https://github.com/johnadam57 "johnadam57 (1 commits)")

---

Tags

pathphpphp-pathfilesystempathfs

### Embed Badge

![Health badge](/badges/lazervel-path/health.svg)

```
[![Health](https://phpackages.com/badges/lazervel-path/health.svg)](https://phpackages.com/packages/lazervel-path)
```

###  Alternatives

[league/flysystem-bundle

Symfony bundle integrating Flysystem into Symfony applications

40029.5M86](/packages/league-flysystem-bundle)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8533.6M194](/packages/league-flysystem-memory)[league/flysystem-async-aws-s3

AsyncAws S3 filesystem adapter for Flysystem.

2610.5M30](/packages/league-flysystem-async-aws-s3)[wikimedia/relpath

Work with file paths to join or find the relative path

11894.3k2](/packages/wikimedia-relpath)[jbzoo/path

PHP virtual path library

1194.7k6](/packages/jbzoo-path)[hdaklue/larapath

A secure, fluent path builder for PHP with sanitization strategies and Laravel 11-12 integration

831.7k](/packages/hdaklue-larapath)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
