[TYPO3-team-core-v5] Getting rid of DIRECTORY_SEPARATOR reloaded
Malte Jansen
mail at maltejansen.de
Sat Jul 26 21:04:07 CEST 2008
Bastian Waidelich schrieb:
> public static function combinePaths(array $paths) {
> $combinedPath = '';
> foreach($paths as $index => $path) {
> $path = self::getUnixStylePath($path);
> if ($index == 0) {
> $path = rtrim($path, '/');
> } else {
> $path = trim($path, '/');
> }
> $combinedPath.= $path . '/';
> }
> return rtrim($combinedPath, '/');
> }
>
> you can pass one or more paths to this function and it will take care of
> slashes and returns a merged Unix style path without trailing slash.
> Some examples:
>
> array('') --> ''
> array('tmp') --> 'tmp'
> array('tmp', 'cache') --> 'tmp/cache'
> array('tmp/cache', 'FLOW3') --> 'tmp/cache/FLOW3'
> array('/var/tmp/', '/FLOW3/MVC/') --> '/var/tmp/FLOW3/MVC'
> array('C:\\WINDOWS\\Temp\\', '/FLOW3/MVC/') --> C:/WINDOWS/Temp/FLOW3/MVC'
>
Hi,
IMO a path should always end with a slash and if function should be
added the pathes in the array should be UnixStyle, so the function will
be faster. Normally you'll have UnixStyled pathes. Only a few PHP
function will return backslashes on windows.
Cheers,
Malte
More information about the TYPO3-team-core-v5
mailing list