PHPackages                             riimu/kit-pathjoin - 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. riimu/kit-pathjoin

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

riimu/kit-pathjoin
==================

Cross-platform library for normalizing and joining file system paths

v1.2.0(8y ago)12603.0k↓19.6%[1 issues](https://github.com/Riimu/Kit-PathJoin/issues)3MITPHPPHP &gt;=5.4.0

Since Dec 8Pushed 8y ago2 watchersCompare

[ Source](https://github.com/Riimu/Kit-PathJoin)[ Packagist](https://packagist.org/packages/riimu/kit-pathjoin)[ Docs](http://kit.riimu.net)[ RSS](/packages/riimu-kit-pathjoin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (3)

Path joiner and normalizer
==========================

[](#path-joiner-and-normalizer)

*PathJoin* is PHP library for normalizing and joining file system paths. The purpose of this library is to make easier to work with file system paths irregardless of the platform and the system directory separator.

The purpose of file path normalization is to provide a single consistent file path representation. In other words, the normalization in this library will resolve `.` and `..` directory references and also condense multiple directory separators into one. This makes it much easier to avoid common problems when comparing paths against each other.

While PHP provides a built in function `realpath()`, it is not usable in every case since it works by using the file system. This library simply combines and normalizes the paths using string handling. There is no requirement for the files or directories to be readable or even exist.

The API documentation is available at:

[![Travis](https://camo.githubusercontent.com/87980c3435a24d4594504ae9e7932ac630cabd8930333e8a5c8e89e97400d74a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5269696d752f4b69742d506174684a6f696e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Riimu/Kit-PathJoin)[![Scrutinizer](https://camo.githubusercontent.com/4dd8d71ea037af5ed4d08140f3c4d303e6cbaaef761c4489c9dd01d8c1dd20f4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f5269696d752f4b69742d506174684a6f696e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/)[![Scrutinizer Coverage](https://camo.githubusercontent.com/bd206b5b71ce3a065a68f351bd34c747494d69c13dbe1d3429b559580d4a7e6a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f5269696d752f4b69742d506174684a6f696e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/)[![Packagist](https://camo.githubusercontent.com/e5f388dbd3ee8a9061d4a7cb1038ab8e89b63f824b4e5cf0e413d3429babf696/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269696d752f6b69742d706174686a6f696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riimu/kit-pathjoin)

Requirements
------------

[](#requirements)

- The minimum supported PHP version is 5.6

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

[](#installation)

### Installation with Composer

[](#installation-with-composer)

The easiest way to install this library is to use Composer to handle your dependencies. In order to install this library via Composer, simply follow these two steps:

1. Acquire the `composer.phar` by running the Composer [Command-line installation](https://getcomposer.org/download/)in your project root.
2. Once you have run the installation script, you should have the `composer.phar`file in you project root and you can run the following command:

    ```
    php composer.phar require "riimu/kit-pathjoin:^1.2"

    ```

After installing this library via Composer, you can load the library by including the `vendor/autoload.php` file that was generated by Composer during the installation.

### Adding the library as a dependency

[](#adding-the-library-as-a-dependency)

If you are already familiar with how to use Composer, you may alternatively add the library as a dependency by adding the following `composer.json` file to your project and running the `composer install` command:

```
{
    "require": {
        "riimu/kit-pathjoin": "^1.2"
    }
}
```

### Manual installation

[](#manual-installation)

If you do not wish to use Composer to load the library, you may also download the library manually by downloading the [latest release](https://github.com/Riimu/Kit-PathJoin/releases/latest)and extracting the `src` folder to your project. You may then include the provided `src/autoload.php` file to load the library classes.

Usage
-----

[](#usage)

This library provides two convenient methods, `Path::normalize()` and `Path::join()`. Both of these methods work in a very similar fashion. The main difference is that while the `join()` method can accept multiple paths to join, the `normalize()` will only accept a single path. Both of the methods will return a normalized path as the result.

The following example will contain numerous different use cases of the library:

```
