src/Path.php
public static function getDirectory($path)
    {
        if ('' === $path) {
            return '';
        }

        $path = static::canonicalize($path);

        // Maintain scheme
        if (false !== ($pos = strpos($path, '://'))) {
            $scheme = substr($path, 0, $pos + 3);
            $path = substr($path, $pos + 3);
        } else {
            $scheme = '';
        }

        if (false !== ($pos = strrpos($path, '/'))) {
            // Directory equals root directory "/"
            if (0 === $pos) {
                return $scheme.'/';
            }

            // Directory equals Windows root "C:/"
            if (2 === $pos && ctype_alpha($path[0]) && ':' === $path[1]) {
                return $scheme.substr($path, 0, 3);
            }

            return $scheme.substr($path, 0, $pos);
        }

        return '';
    }
public static function getDirectory($path)
    {
        if ('' === $path) {
            return '';
        }

        $path = static::canonicalize($path);

        // Maintain scheme
        if (false !== ($pos = strpos($path, '://'))) {
            $scheme = substr($path, 0, $pos + 3);
            $path = substr($path, $pos + 3);
        } else {
            $scheme = '';
        }

        if (false !== ($pos = strrpos($path, '/'))) {
            // Directory equals root directory "/"
            if (0 === $pos) {
                return $scheme.'/';
            }

            // Directory equals Windows root "C:/"
            if (2 === $pos && ctype_alpha($path[0]) && ':' === $path[1]) {
                return $scheme.substr($path, 0, 3);
            }

            return $scheme.substr($path, 0, $pos);
        }

        return '';
    }
public static function getDirectory ( $ path ) { if ( '' === $ path ) { return '' ; } $ path = static :: canonicalize ( $ path ) ; // Maintain scheme if ( false !== ( $ pos = strpos ( $ path , '://' ) ) ) { $ scheme = substr ( $ path , 0 , $ pos + 3 ) ; $ path = substr ( $ path , $ pos + 3 ) ; } else { $ scheme = '' ; } if ( false !== ( $ pos = strrpos ( $ path , '/' ) ) ) { // Directory equals root directory "/" if ( 0 === $ pos ) { return $ scheme . '/' ; } // Directory equals Windows root "C:/" if ( 2 === $ pos && ctype_alpha ( $ path [ 0 ] ) && ':' === $ path [ 1 ] ) { return $ scheme . substr ( $ path , 0 , 3 ) ; } return $ scheme . substr ( $ path , 0 , $ pos ) ; } return '' ; }
Returns the directory part of the path.

This method is similar to PHP's dirname(), but handles various cases
where dirname() returns a weird result:

- dirname() does not accept backslashes on UNIX
- dirname("C:/webmozart") returns "C:", not "C:/"
- dirname("C:/") returns ".", not "C:/"
- dirname("C:") returns ".", not "C:/"
- dirname("webmozart") returns ".", not ""
- dirname() does not canonicalize the result

This method fixes these shortcomings and behaves like dirname()
otherwise.

The result is a canonical path.

@param string $path A path string.

@return string The canonical directory part. Returns the root directory
if the root directory is passed. Returns an empty string
if a relative path is passed that contains no slashes.
Returns an empty string if an empty string is passed.

@since 1.0 Added method.
@since 2.0 Method now fails if $path is not a string.
Returns the directory part of the path .