Oihana PHP

splitPath.php

Table of Contents

Functions

splitPath()  : array<string|int, string>
Splits a **canonical** filesystem path into two parts: 1. **Root** : the protocol / drive / leading slash portion 2. **Remainder** : the sub‑path that follows

Functions

splitPath()

Splits a **canonical** filesystem path into two parts: 1. **Root** : the protocol / drive / leading slash portion 2. **Remainder** : the sub‑path that follows

splitPath(string $path) : array<string|int, string>

Supported patterns

Input example Returned root Returned remainder
/var/www/html / var/www/html
C:/Windows/System32 C:/ Windows/System32
C: C:/ (empty)
file:///home/user/docs file:/// home/user/docs
\\\\server\\share\\folder (UNC) // server/share/folder

Note : The input path is assumed to be canonical (slashes normalisés à /, pas de segments . ou ..). The function does not perform any filesystem checks.

Parameters
$path : string

Canonical path (absolute or relative, UNIX or Windows, with optional URL‑style scheme).

Tags
example
[$root, $rest] = splitPath('/etc/nginx/nginx.conf');
// $root = '/' | $rest = 'etc/nginx/nginx.conf'

[$root, $rest] = splitPath('C:/Program Files');
// $root = 'C:/' | $rest = 'Program Files'

[$root, $rest] = splitPath('C:');
// $root = 'C:/' | $rest = ''

[$root, $rest] = splitPath('file:///var/log');
// $root = 'file:///' | $rest = 'var/log'
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
array<string|int, string>

An array with [0] => root, [1] => remainder. Both strings can be empty.


        
On this page

Search results