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