PHPackages                             webmozart/path-util - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. webmozart/path-util

Abandoned → [symfony/filesystem](/?search=symfony%2Ffilesystem)Library[Utility &amp; Helpers](/categories/utility)

webmozart/path-util
===================

A robust cross-platform utility for normalizing, comparing and modifying file paths.

2.3.0(10y ago)47088.7M—3.5%24[7 issues](https://github.com/webmozart/path-util/issues)[4 PRs](https://github.com/webmozart/path-util/pulls)20MITPHPPHP &gt;=5.3.3

Since Nov 26Pushed 4y ago8 watchersCompare

[ Source](https://github.com/webmozart/path-util)[ Packagist](https://packagist.org/packages/webmozart/path-util)[ RSS](/packages/webmozart-path-util/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (13)Used By (20)

File Path Utility
=================

[](#file-path-utility)

[![Build Status](https://camo.githubusercontent.com/1f60388903a94f3629468b9cd3413bf8507554792802c8b838613aa4c03839e1/68747470733a2f2f7472617669732d63692e6f72672f7765626d6f7a6172742f706174682d7574696c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/webmozart/path-util)[![Build status](https://camo.githubusercontent.com/a7628f959972bd4ae2d51d1273688a2fbaf06274288baae3fd57914be4819f6d/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f643575757970723670313632677078662f6272616e63682f6d61737465723f7376673d74727565)](https://ci.appveyor.com/project/webmozart/path-util/branch/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e602033bb6c44b333db1e727887d54130731d3fd6300190ebee64b4a596eab93/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7765626d6f7a6172742f706174682d7574696c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/webmozart/path-util/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/283a4bf6732845e6f178288fe1a2027b8d7f35468a5bf2c32f6f216592cd9b42/68747470733a2f2f706f7365722e707567782e6f72672f7765626d6f7a6172742f706174682d7574696c2f762f737461626c652e737667)](https://packagist.org/packages/webmozart/path-util)[![Total Downloads](https://camo.githubusercontent.com/79fc94c3c168777ae643d4d6190af7a027f7cde5ca03c72e484b840464f80dbe/68747470733a2f2f706f7365722e707567782e6f72672f7765626d6f7a6172742f706174682d7574696c2f646f776e6c6f6164732e737667)](https://packagist.org/packages/webmozart/path-util)[![Dependency Status](https://camo.githubusercontent.com/aa6ff82c0d6d45896ca129a73cadec2fdf3736dd82b7a3d36dd3e4f00d52f1cd/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f7765626d6f7a6172743a706174682d7574696c2f322e332e302f62616467652e737667)](https://www.versioneye.com/php/webmozart:path-util/2.3.0)

Latest release: [2.3.0](https://packagist.org/packages/webmozart/path-util#2.3.0)

PHP &gt;= 5.3.3

This package provides robust, cross-platform utility functions for normalizing, comparing and modifying file paths and URLs.

Deprecation
-----------

[](#deprecation)

This package has been merged into [the Symfony Filesystem Component 5.4](https://github.com/symfony/filesystem/tree/5.4). It is not maintained anymore.

Installation
------------

[](#installation)

The utility can be installed with [Composer](https://getcomposer.org):

```
$ composer require webmozart/path-util

```

Usage
-----

[](#usage)

Use the `Path` class to handle file paths:

```
use Webmozart\PathUtil\Path;

echo Path::canonicalize('/var/www/vhost/webmozart/../config.ini');
// => /var/www/vhost/config.ini

echo Path::canonicalize('C:\Programs\Webmozart\..\config.ini');
// => C:/Programs/config.ini

echo Path::canonicalize('~/config.ini');
// => /home/webmozart/config.ini

echo Path::makeAbsolute('config/config.yml', '/var/www/project');
// => /var/www/project/config/config.yml

echo Path::makeRelative('/var/www/project/config/config.yml', '/var/www/project/uploads');
// => ../config/config.yml

$paths = array(
    '/var/www/vhosts/project/httpdocs/config/config.yml',
    '/var/www/vhosts/project/httpdocs/images/banana.gif',
    '/var/www/vhosts/project/httpdocs/uploads/../images/nicer-banana.gif',
);

Path::getLongestCommonBasePath($paths);
// => /var/www/vhosts/project/httpdocs

Path::getFilename('/views/index.html.twig');
// => index.html.twig

Path::getFilenameWithoutExtension('/views/index.html.twig');
// => index.html

Path::getFilenameWithoutExtension('/views/index.html.twig', 'html.twig');
Path::getFilenameWithoutExtension('/views/index.html.twig', '.html.twig');
// => index

Path::getExtension('/views/index.html.twig');
// => twig

Path::hasExtension('/views/index.html.twig');
// => true

Path::hasExtension('/views/index.html.twig', 'twig');
// => true

Path::hasExtension('/images/profile.jpg', array('jpg', 'png', 'gif'));
// => true

Path::changeExtension('/images/profile.jpeg', 'jpg');
// => /images/profile.jpg

Path::join('phar://C:/Documents', 'projects/my-project.phar', 'composer.json');
// => phar://C:/Documents/projects/my-project.phar/composer.json

Path::getHomeDirectory();
// => /home/webmozart
```

Use the `Url` class to handle URLs:

```
use Webmozart\PathUtil\Url;

echo Url::makeRelative('http://example.com/css/style.css', 'http://example.com/puli');
// => ../css/style.css

echo Url::makeRelative('http://cdn.example.com/css/style.css', 'http://example.com/puli');
// => http://cdn.example.com/css/style.css
```

Learn more in the [Documentation](docs/usage.md) and the [API Docs](https://webmozart.github.io/path-util/api/latest/class-Webmozart.PathUtil.Path.html).

Authors
-------

[](#authors)

- [Bernhard Schussek](http://webmozarts.com) a.k.a. [@webmozart](https://twitter.com/webmozart)
- [The Community Contributors](https://github.com/webmozart/path-util/graphs/contributors)

Documentation
-------------

[](#documentation)

Read the [Documentation](docs/usage.md) if you want to learn more about the contained functions.

Contribute
----------

[](#contribute)

Contributions are always welcome!

- Report any bugs or issues you find on the [issue tracker](https://github.com/webmozart/path-util/issues).
- You can grab the source code at the [Git repository](https://github.com/webmozart/path-util).

Support
-------

[](#support)

If you are having problems, send a mail to  or shout out to [@webmozart](https://twitter.com/webmozart) on Twitter.

License
-------

[](#license)

All contents of this package are licensed under the [MIT license](LICENSE).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity71

Solid adoption and visibility

Community42

Growing community involvement

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 72.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

Every ~38 days

Recently: every ~31 days

Total

11

Last Release

3806d ago

Major Versions

1.1.0 → 2.0.02015-05-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/00803e109877ea9de0995e81c928871a595781bd6ea227092bfd7c6df5af58f0?d=identicon)[webmozart](/maintainers/webmozart)

---

Top Contributors

[![webmozart](https://avatars.githubusercontent.com/u/176399?v=4)](https://github.com/webmozart "webmozart (91 commits)")[![SenseException](https://avatars.githubusercontent.com/u/859964?v=4)](https://github.com/SenseException "SenseException (18 commits)")[![King2500](https://avatars.githubusercontent.com/u/4896363?v=4)](https://github.com/King2500 "King2500 (8 commits)")[![DavidBadura](https://avatars.githubusercontent.com/u/470138?v=4)](https://github.com/DavidBadura "DavidBadura (4 commits)")[![hason](https://avatars.githubusercontent.com/u/288535?v=4)](https://github.com/hason "hason (1 commits)")[![harikt](https://avatars.githubusercontent.com/u/120454?v=4)](https://github.com/harikt "harikt (1 commits)")[![tgalopin](https://avatars.githubusercontent.com/u/1651494?v=4)](https://github.com/tgalopin "tgalopin (1 commits)")[![h4cc](https://avatars.githubusercontent.com/u/2981491?v=4)](https://github.com/h4cc "h4cc (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[phpdocumentor/reflection-docblock

With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.

9.4k722.2M1.2k](/packages/phpdocumentor-reflection-docblock)[icanhazstring/composer-unused

Show unused packages by scanning your code

1.7k7.0M188](/packages/icanhazstring-composer-unused)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12521.4M109](/packages/phpdocumentor-reflection)[sylius/fixtures-bundle

Configurable fixtures for Symfony applications.

517.7M12](/packages/sylius-fixtures-bundle)[sylius/promotion

Flexible promotion management for PHP applications.

28477.8k9](/packages/sylius-promotion)

PHPackages © 2026

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