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.
public static getDirectory ( string $path ) : string | ||
$path | string | 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. |