= 1) { // Rremove this and previous element array_splice($pathParts, $partCount - 1, 2); $partCount -= 2; $pathPartsLength -= 2; } elseif ($absolutePathPrefix) { // can't go higher than root dir // simply remove this part and continue array_splice($pathParts, $partCount, 1); $partCount--; $pathPartsLength--; } } } return $absolutePathPrefix . implode('/', $pathParts); } /** * Checks if the $path is absolute or relative (detecting either '/' or * 'x:/' as first part of string) and returns TRUE if so. * * @param string $path File path to evaluate * @return bool */ private static function isAbsolutePath($path) { // Path starting with a / is always absolute, on every system // On Windows also a path starting with a drive letter is absolute: X:/ return (isset($path[0]) ? $path[0] : null) === '/' || static::isWindows() && ( strpos($path, ':/') === 1 || strpos($path, ':\\') === 1 ); } /** * @return bool */ private static function isWindows() { return stripos(PHP_OS, 'WIN') === 0; } }