getRoot.php
Table of Contents
Functions
- getRoot() : string
- Extracts the root directory component of a given path.
Functions
getRoot()
Extracts the root directory component of a given path.
getRoot(string $path) : string
This function identifies the root portion of a file system path, including handling of protocol schemes. ( e.g., "file://", "s3://" )
UNIX root ("/"), and Windows root ( e.g., "C:/" ).
It returns the canonical root as a string, or an empty string if the path is relative or empty.
Behavior:
"file:///usr/bin"
→"file:///"
"/usr/bin"
→"/"
"C:\\Windows\\System32"
→"C:/"
"relative/path"
→""
(empty string)
Parameters
- $path : string
-
The input path, optionally with a scheme.
Tags
Return values
string —The root component of the path, or an empty string if no root can be determined.