PHPackages                             jackiedo/path-helper - 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. jackiedo/path-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jackiedo/path-helper
====================

Helper class for working with local paths in PHP

v1.0.0(4y ago)2286.1k↓18.8%9MITPHPPHP &gt;=5.4.0

Since Mar 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/JackieDo/Path-Helper)[ Packagist](https://packagist.org/packages/jackiedo/path-helper)[ Docs](https://github.com/JackieDo/path-helper)[ RSS](/packages/jackiedo-path-helper/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)DependenciesVersions (2)Used By (9)

Path Helper
===========

[](#path-helper)

[![Latest Stable Version](https://camo.githubusercontent.com/077ac726a950db4d4a2c3da603117a2e2d46cd7b2d824fadb0bfe67da39ebd1e/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f706174682d68656c7065722f76)](//packagist.org/packages/jackiedo/path-helper)[![Total Downloads](https://camo.githubusercontent.com/b26f8d2259f8500dc86a01a9bbdbd478663b13037da5e7d6862904829a0d0fb4/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f706174682d68656c7065722f646f776e6c6f616473)](//packagist.org/packages/jackiedo/path-helper)[![Latest Unstable Version](https://camo.githubusercontent.com/64899c2d3838d53e766f63634e7bcd73acd16166e3fa7f0e5d6acc8aba91390e/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f706174682d68656c7065722f762f756e737461626c65)](//packagist.org/packages/jackiedo/path-helper)[![License](https://camo.githubusercontent.com/44941a1e69fdad15380a9d1886b2e5b53c13dbadaf83d56bffabb17e6cc23d70/68747470733a2f2f706f7365722e707567782e6f72672f6a61636b6965646f2f706174682d68656c7065722f6c6963656e7365)](//packagist.org/packages/jackiedo/path-helper)

Helper class for working with local paths in PHP.

Compatibility
=============

[](#compatibility)

This package requires PHP 5.4.0 or later.

Overview
========

[](#overview)

Look at one of the following topics to learn more about Path Helper

- [Path Helper](#path-helper)
- [Compatibility](#compatibility)
- [Overview](#overview)
    - [Installation](#installation)
    - [Usage](#usage)
        - [Using static method](#using-static-method)
        - [Using method of instance](#using-method-of-instance)
        - [Using built-in function](#using-built-in-function)
    - [Available methods](#available-methods)
        - [Normalize the directory separators of the path](#normalize-the-directory-separators-of-the-path)
        - [Restyle the path](#restyle-the-path)
            - [Restyle to Unix style](#restyle-to-unix-style)
            - [Restyle to Windows style](#restyle-to-windows-style)
            - [Restyle belong to current OS](#restyle-belong-to-current-os)
        - [Create the absolute path](#create-the-absolute-path)
        - [Create the relative path](#create-the-relative-path)
        - [Check the form of the path](#check-the-form-of-the-path)
            - [Check the absolute form](#check-the-absolute-form)
            - [Check the relative form](#check-the-relative-form)
        - [Check the mutual wrapping of paths](#check-the-mutual-wrapping-of-paths)
            - [Check if the path is ancestor of another](#check-if-the-path-is-ancestor-of-another)
            - [Check if the path is descendant of another](#check-if-the-path-is-descendant-of-another)
    - [Available functions](#available-functions)
- [License](#license)

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

[](#installation)

[Download a latest package](https://github.com/JackieDo/Path-Helper/releases/latest) or use [Composer](http://getcomposer.org/):

```
$ composer require jackiedo/path-helper
```

Usage
-----

[](#usage)

After requiring composer autoloader, you can use the package in the following ways:

### Using static method

[](#using-static-method)

```
use Jackiedo\PathHelper\Path;

// ...

$return = Path::doSomething();
```

### Using method of instance

[](#using-method-of-instance)

```
use Jackiedo\PathHelper\Path;

// ...

$helper = new Path;
$return = $helper->doSomething();
```

### Using built-in function

[](#using-built-in-function)

See [here](#available-functions) for more details.

Available methods
-----------------

[](#available-methods)

### Normalize the directory separators of the path

[](#normalize-the-directory-separators-of-the-path)

Formats the directory separators of a given path with a specific string.

**Syntax:**

```
/**
 * Formats the directory separators of a given path with a specific string.
 *
 * @param string $path      the path want to normalize
 * @param string $separator the directory separator want to use
 *
 * @return string
 */
public static function normalize($path, $separator = DIRECTORY_SEPARATOR);
```

**Example:**

```
$return1 = Path::normalize('path\\to/specific/file/or\\directory');
// The result returned will depend on the operating system
//     On Windows -> path\to\specific\file\or\directory
//     On Unix    -> path/to/specific/file/or/directory

$return2 = Path::normalize('path\\to/specific/file/or\\directory', '/');
// path/to/specific/file/or/directory

$return3 = Path::normalize('path\\to/specific/file/or\\directory', ' > ');
// path > to > specific > file > or > directory
```

### Restyle the path

[](#restyle-the-path)

#### Restyle to Unix style

[](#restyle-to-unix-style)

Alternative to `normalize($path, '/')` method.

**Syntax:**

```
/**
 * Normalize directory separators of a given path according to Unix OS style.
 *
 * @param string $path the path want to normalize
 *
 * @return string
 */
public static function unixStyle($path);
```

**Example:**

```
$return = Path::unixStyle('path\\to/specific/file/or\\directory');
// path/to/specific/file/or/directory
```

#### Restyle to Windows style

[](#restyle-to-windows-style)

Alternative to `normalize($path, '\\')` method.

**Syntax:**

```
/**
 * Normalize directory separators of a given path according to Windows OS style.
 *
 * @param string $path the path want to normalize
 *
 * @return string
 */
public static function winStyle($path);
```

**Example:**

```
$return = Path::winStyle('path\\to/specific/file/or\\directory');
// path\to\specific\file\or\directory
```

#### Restyle belong to current OS

[](#restyle-belong-to-current-os)

Alternative to `normalize($path, DIRECTORY_SEPARATOR)` method.

**Syntax:**

```
/**
 * Normalize directory separators of a given path according to the current OS style.
 *
 * @param string $path the path want to normalize
 *
 * @return string
 */
public static function osStyle($path);
```

**Example:**

```
$return = Path::osStyle('path\\to/specific/file/or\\directory');
// The result returned will depend on the operating system
//     On Windows -> path\to\specific\file\or\directory
//     On Unix    -> path/to/specific/file/or/directory
```

### Create the absolute path

[](#create-the-absolute-path)

Create the absolute path from a given path.

**Syntax:**

```
/**
 * Return absolute path from a given path.
 *
 * This method is an alternative to `realpath()` function for non-existent paths.
 *
 * @param string $path      the path want to format
 * @param string $separator the directory separator want to use in the result
 *
 * @return string
 */
public static function absolute($path, $separator = DIRECTORY_SEPARATOR);
```

**Example:**

```
$return = Path::absolute('./this\\is/../sample/path');
// The result returned will depend on the operating system and current working directory
// You will probably get the following result: /home/www/public_html/this/sample/path
```

**Note:**

This method looks like PHP's `realpath()` function at first glance, but it actually works in a different way.

> The `realpath()` function returns the absolute path to the `existing` directory or file, while this method `does not check` for actual existence.

### Create the relative path

[](#create-the-relative-path)

Create the relative path from a given file or directory to another location.

**Syntax:**

```
/**
 * Return relative path from a given file or directory to another location.
 *
 * @param string $from      the path of departure file or directory
 * @param string $to        the path of destination file or directory
 * @param string $separator the directory separator want to use in the result
 *
 * @return string
 */
public static function relative($from, $to, $separator = DIRECTORY_SEPARATOR);
```

**Example:**

```
$return = Path::absolute('./this\\is/../sample/path', '/home/www/another/directory');
// The result returned will depend on the operating system and current working directory
// You will probably get the following result: ../../../../another/directory
```

### Check the form of the path

[](#check-the-form-of-the-path)

#### Check the absolute form

[](#check-the-absolute-form)

**Syntax:**

```
/**
 * Check if a given path is an absolute path.
 *
 * @param string $path the path want to check
 *
 * @return bool
 */
public static function isAbsolute($path);
```

**Example:**

```
$return = Path::isAbsolute('/home/www/public_html');      // true
$return = Path::isAbsolute('sample/../path');             // false
$return = Path::isAbsolute('D:\\home\\www\\public_html'); // true
$return = Path::isAbsolute('sample\\..\\path');           // false
```

#### Check the relative form

[](#check-the-relative-form)

**Syntax:**

```
/**
 * Check if a given path is a relative path.
 *
 * @param string $path the path want to check
 *
 * @return bool
 */
public static function isRelative($path);
```

**Example:**

```
$return = Path::isRelative('/home/www/public_html');      // false
$return = Path::isRelative('sample/../path');             // true
$return = Path::isRelative('D:\\home\\www\\public_html'); // false
$return = Path::isRelative('sample\\..\\path');           // true
```

### Check the mutual wrapping of paths

[](#check-the-mutual-wrapping-of-paths)

#### Check if the path is ancestor of another

[](#check-if-the-path-is-ancestor-of-another)

**Syntax:**

```
/**
 * Check if a given path is ancestor of the another path.
 *
 * Return true if the input path is ancestor of the comparison
 *
 * @param string $path       the path want to check
 * @param string $comparison the target path used for comparison
 *
 * @return bool
 */
public static function isAncestor($path, $comparison);
```

**Example:**

```
$return = Path::isAncestor('/home/www', '/home/www/public/assets/css/../images/sample.png');     // true
$return = Path::isAncestor('/home/www', '/another_home/public/assets/css/../images/sample.png'); // false
```

#### Check if the path is descendant of another

[](#check-if-the-path-is-descendant-of-another)

**Syntax:**

```
/**
 * Check if a given path is descendant of the another path.
 *
 * Return true if the input path is descendant of the comparison
 *
 * @param string $path       the path want to check
 * @param string $comparison the target path used for comparison
 *
 * @return bool
 */
public static function isDescendant($path, $comparison);
```

**Example:**

```
$return = Path::isDescendant('/home/www/public/assets/css/../images/sample.png', '/home/www');     // true
$return = Path::isDescendant('/another_home/public/assets/css/../images/sample.png', '/home/www'); // false
```

Available functions
-------------------

[](#available-functions)

This package contains several built-in `functions` to alternative using the `methods` of the `Path` class. However, the use of these functions is `not recommended`, because they may conflict with the functions of other packages.

FunctionClass method*absolute\_path()**Path::absolute()**relative\_path()**Path::relative()**winstyle\_path()**Path::winStyle()**unixstyle\_path()**Path::unixStyle()**osstyle\_path()**Path::osStyle()**normalize\_path()**Path::normalize()**is\_absolute\_path()**Path::isAbsolute()**is\_relative\_path()**Path::isRelative()**is\_descendant\_path()**Path::isDescendant()**is\_ancestor\_path()**Path::isAncestor()*License
=======

[](#license)

[MIT](https://github.com/JackieDo/Path-Helper/blob/master/LICENSE) © Jackie Do

###  Health Score

32

—

LowBetter than 70% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

1555d ago

### Community

Maintainers

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

---

Top Contributors

[![JackieDo](https://avatars.githubusercontent.com/u/9862115?v=4)](https://github.com/JackieDo "JackieDo (19 commits)")

---

Tags

helperhelperslibrarypathpathsphpphphelperhelperslibrarypathpaths

### Embed Badge

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

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

PHPackages © 2026

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