4 [![Build Status](https://travis-ci.org/webmozart/path-util.svg?branch=2.3.0)](https://travis-ci.org/webmozart/path-util)
5 [![Build status](https://ci.appveyor.com/api/projects/status/d5uuypr6p162gpxf/branch/master?svg=true)](https://ci.appveyor.com/project/webmozart/path-util/branch/master)
6 [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/webmozart/path-util/badges/quality-score.png?b=2.3.0)](https://scrutinizer-ci.com/g/webmozart/path-util/?branch=2.3.0)
7 [![Latest Stable Version](https://poser.pugx.org/webmozart/path-util/v/stable.svg)](https://packagist.org/packages/webmozart/path-util)
8 [![Total Downloads](https://poser.pugx.org/webmozart/path-util/downloads.svg)](https://packagist.org/packages/webmozart/path-util)
9 [![Dependency Status](https://www.versioneye.com/php/webmozart:path-util/2.3.0/badge.svg)](https://www.versioneye.com/php/webmozart:path-util/2.3.0)
11 Latest release: [2.3.0](https://packagist.org/packages/webmozart/path-util#2.3.0)
15 This package provides robust, cross-platform utility functions for normalizing,
16 comparing and modifying file paths and URLs.
21 The utility can be installed with [Composer]:
24 $ composer require webmozart/path-util
30 Use the `Path` class to handle file paths:
33 use Webmozart\PathUtil\Path;
35 echo Path::canonicalize('/var/www/vhost/webmozart/../config.ini');
36 // => /var/www/vhost/config.ini
38 echo Path::canonicalize('C:\Programs\Webmozart\..\config.ini');
39 // => C:/Programs/config.ini
41 echo Path::canonicalize('~/config.ini');
42 // => /home/webmozart/config.ini
44 echo Path::makeAbsolute('config/config.yml', '/var/www/project');
45 // => /var/www/project/config/config.yml
47 echo Path::makeRelative('/var/www/project/config/config.yml', '/var/www/project/uploads');
48 // => ../config/config.yml
51 '/var/www/vhosts/project/httpdocs/config/config.yml',
52 '/var/www/vhosts/project/httpdocs/images/banana.gif',
53 '/var/www/vhosts/project/httpdocs/uploads/../images/nicer-banana.gif',
56 Path::getLongestCommonBasePath($paths);
57 // => /var/www/vhosts/project/httpdocs
59 Path::getFilename('/views/index.html.twig');
62 Path::getFilenameWithoutExtension('/views/index.html.twig');
65 Path::getFilenameWithoutExtension('/views/index.html.twig', 'html.twig');
66 Path::getFilenameWithoutExtension('/views/index.html.twig', '.html.twig');
69 Path::getExtension('/views/index.html.twig');
72 Path::hasExtension('/views/index.html.twig');
75 Path::hasExtension('/views/index.html.twig', 'twig');
78 Path::hasExtension('/images/profile.jpg', array('jpg', 'png', 'gif'));
81 Path::changeExtension('/images/profile.jpeg', 'jpg');
82 // => /images/profile.jpg
84 Path::join('phar://C:/Documents', 'projects/my-project.phar', 'composer.json');
85 // => phar://C:/Documents/projects/my-project.phar/composer.json
87 Path::getHomeDirectory();
91 Use the `Url` class to handle URLs:
94 use Webmozart\PathUtil\Url;
96 echo Url::makeRelative('http://example.com/css/style.css', 'http://example.com/puli');
97 // => ../css/style.css
99 echo Url::makeRelative('http://cdn.example.com/css/style.css', 'http://example.com/puli');
100 // => http://cdn.example.com/css/style.css
103 Learn more in the [Documentation] and the [API Docs].
108 * [Bernhard Schussek] a.k.a. [@webmozart]
109 * [The Community Contributors]
114 Read the [Documentation] if you want to learn more about the contained functions.
119 Contributions are always welcome!
121 * Report any bugs or issues you find on the [issue tracker].
122 * You can grab the source code at the [Git repository].
127 If you are having problems, send a mail to bschussek@gmail.com or shout out to
128 [@webmozart] on Twitter.
133 All contents of this package are licensed under the [MIT license].
135 [Bernhard Schussek]: http://webmozarts.com
136 [The Community Contributors]: https://github.com/webmozart/path-util/graphs/contributors
137 [Composer]: https://getcomposer.org
138 [Documentation]: docs/usage.md
139 [API Docs]: https://webmozart.github.io/path-util/api/latest/class-Webmozart.PathUtil.Path.html
140 [issue tracker]: https://github.com/webmozart/path-util/issues
141 [Git repository]: https://github.com/webmozart/path-util
142 [@webmozart]: https://twitter.com/webmozart
143 [MIT license]: LICENSE