function Path::split
Splits a canonical path into its root directory and the remainder.
If the path has no root directory, an empty root directory will be returned.
If the root directory is a Windows style partition, the resulting root will always contain a trailing slash.
list ($root, $path) = Path::split("C:/symfony") // => ["C:/", "symfony"]
list ($root, $path) = Path::split("C:") // => ["C:/", ""]
Return value
array{string, string} an array with the root directory and the remaining relative path
3 calls to Path::split()
- Path::canonicalize in vendor/
symfony/ filesystem/ Path.php - Canonicalizes the given path.
- Path::getLongestCommonBasePath in vendor/
symfony/ filesystem/ Path.php - Returns the longest common base path in canonical form of a set of paths or `null` if the paths are on different Windows partitions.
- Path::makeRelative in vendor/
symfony/ filesystem/ Path.php - Turns a path into a relative path.
File
-
vendor/
symfony/ filesystem/ Path.php, line 769
Class
- Path
- Contains utility methods for handling path strings.
Namespace
Symfony\Component\FilesystemCode
private static function split(string $path) : array {
if ('' === $path) {
return [
'',
'',
];
}
// Remember scheme as part of the root, if any
if (false !== ($schemeSeparatorPosition = strpos($path, '://'))) {
$root = substr($path, 0, $schemeSeparatorPosition + 3);
$path = substr($path, $schemeSeparatorPosition + 3);
}
else {
$root = '';
}
$length = \strlen($path);
// Remove and remember root directory
if (str_starts_with($path, '/')) {
$root .= '/';
$path = $length > 1 ? substr($path, 1) : '';
}
elseif ($length > 1 && ctype_alpha($path[0]) && ':' === $path[1]) {
if (2 === $length) {
// Windows special case: "C:"
$root .= $path . '/';
$path = '';
}
elseif ('/' === $path[2]) {
// Windows normal case: "C:/"..
$root .= substr($path, 0, 3);
$path = $length > 3 ? substr($path, 3) : '';
}
}
return [
$root,
$path,
];
}