Oihana PHP

joinPaths.php

Table of Contents

Functions

joinPaths()  : string
Concatenates multiple path fragments into a single canonical path.

Functions

joinPaths()

Concatenates multiple path fragments into a single canonical path.

joinPaths(string ...$paths) : string

Behaviour rules

  1. Empty segments ('') are ignored.
  2. The first non‑empty segment is kept “as‑is” so a leading slash, drive letter (C:/), or scheme (phar://) is preserved.
  3. Every subsequent segment is joined with exactly one forward‑slash (/) separator – unless the previous fragment already ends with / or \.
  4. After assembly, the result is passed through canonicalizePath() to normalise slashes and collapse . / ...
  5. If all fragments are empty, an empty string is returned.

Type‑hint fix – the function returns a string, not a bool. The signature has been updated accordingly.

Parameters
$paths : string

Arbitrary number of path fragments. May contain Unix, Windows or URL‑style segments.

Tags
example
joinPaths('/var', 'log', 'app.log');
// → '/var/log/app.log'

joinPaths('C:\\', 'Temp', '..', 'Logs');
// → 'C:/Logs'

joinPaths('phar://archive.phar', '/sub', '/file.php');
// → 'phar://archive.phar/sub/file.php'

joinPaths('', 'relative', 'path');   // leading blanks ignored
// → 'relative/path'
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

Canonical, joined path (or empty string).


        
On this page

Search results