public static function normalizePath($filepath, $separator = DIRECTORY_SEPARATOR, $removeTrailing = true)
    {
        $scheme = '';
        if (false !== $parseUrl = parse_url($filepath)) {
            $auth = isset($parseUrl['user']) ? $parseUrl['user'] : '';
            $auth .= isset($parseUrl['pass']) ? ':' . $parseUrl['pass'] : '';
            $auth .= (isset($parseUrl['user']) || isset($parseUrl['pass'])) ? '@' : '';
            $scheme .= isset($parseUrl['scheme']) ? $parseUrl['scheme'] . ':' : '';
            $scheme .= isset($parseUrl['host']) ? '//' . $auth . $parseUrl['host'] : '';
            $scheme .= isset($parseUrl['port']) ? ':' . $parseUrl['port'] : '';

            if (isset($parseUrl['path'])) {
                $filepath = $parseUrl['path'];
            }

            if (isset($parseUrl['scheme']) && isset($parseUrl['host'])) {
                $separator = '/';
            }
        }

        $patterns = array('/\//', '/\\\\/', '/\/+/');
        $replacements = array_fill(0, 3, '/');

        if (true === $removeTrailing) {
            $patterns[] = '/\/$/';
            $replacements[] = '';
        }

        return str_replace('/', $separator, $scheme.preg_replace($patterns, $replacements, $filepath));
    }
public static function normalizePath($filepath, $separator = DIRECTORY_SEPARATOR, $removeTrailing = true)
    {
        $scheme = '';
        if (false !== $parseUrl = parse_url($filepath)) {
            $auth = isset($parseUrl['user']) ? $parseUrl['user'] : '';
            $auth .= isset($parseUrl['pass']) ? ':' . $parseUrl['pass'] : '';
            $auth .= (isset($parseUrl['user']) || isset($parseUrl['pass'])) ? '@' : '';
            $scheme .= isset($parseUrl['scheme']) ? $parseUrl['scheme'] . ':' : '';
            $scheme .= isset($parseUrl['host']) ? '//' . $auth . $parseUrl['host'] : '';
            $scheme .= isset($parseUrl['port']) ? ':' . $parseUrl['port'] : '';

            if (isset($parseUrl['path'])) {
                $filepath = $parseUrl['path'];
            }

            if (isset($parseUrl['scheme']) && isset($parseUrl['host'])) {
                $separator = '/';
            }
        }

        $patterns = array('/\//', '/\\\\/', '/\/+/');
        $replacements = array_fill(0, 3, '/');

        if (true === $removeTrailing) {
            $patterns[] = '/\/$/';
            $replacements[] = '';
        }

        return str_replace('/', $separator, $scheme.preg_replace($patterns, $replacements, $filepath));
    }
public static function normalizePath ( $ filepath , $ separator = DIRECTORY_SEPARATOR , $ removeTrailing = true ) { $ scheme = '' ; if ( false !== $ parseUrl = parse_url ( $ filepath ) ) { $ auth = isset ( $ parseUrl [ 'user' ] ) ? $ parseUrl [ 'user' ] : '' ; $ auth .= isset ( $ parseUrl [ 'pass' ] ) ? ':' . $ parseUrl [ 'pass' ] : '' ; $ auth .= ( isset ( $ parseUrl [ 'user' ] ) || isset ( $ parseUrl [ 'pass' ] ) ) ? '@' : '' ; $ scheme .= isset ( $ parseUrl [ 'scheme' ] ) ? $ parseUrl [ 'scheme' ] . ':' : '' ; $ scheme .= isset ( $ parseUrl [ 'host' ] ) ? '//' . $ auth . $ parseUrl [ 'host' ] : '' ; $ scheme .= isset ( $ parseUrl [ 'port' ] ) ? ':' . $ parseUrl [ 'port' ] : '' ; if ( isset ( $ parseUrl [ 'path' ] ) ) { $ filepath = $ parseUrl [ 'path' ] ; } if ( isset ( $ parseUrl [ 'scheme' ] ) && isset ( $ parseUrl [ 'host' ] ) ) { $ separator = '/' ; } } $ patterns = array ( '/\//' , '/\\\\/' , '/\/+/' ) ; $ replacements = array_fill ( 0 , 3 , '/' ) ; if ( true === $ removeTrailing ) { $ patterns [ ] = '/\/$/' ; $ replacements [ ] = '' ; } return str_replace ( '/' , $ separator , $ scheme . preg_replace ( $ patterns , $ replacements , $ filepath ) ) ; }
Normalize a file path according to the system characteristics
@param  string  $filepath       the path to normalize
@param  string  $separator      The directory separator to use
@param  boolean $removeTrailing Removing trailing separators to the end of path
@return string  The normalize file path
Normalize a file path according to the system characteristics