函数原型
path_is_absolute( string $path ): bool
函数描述
Tests if a given filesystem path is absolute.
是否弃用
未弃用
函数参数
-
$path
string
Required - File path.
函数返回值
bool True if path is absolute, false is not absolute.
函数位置
File: wp-includes/functions.php.
函数源码
function path_is_absolute( $path ) {
/*
* Check to see if the path is a stream and check to see if its an actual
* path or file as realpath() does not support stream wrappers.
*/
if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) {
return true;
}
/*
* This is definitive if true but fails if $path does not exist or contains
* a symbolic link.
*/
if ( realpath( $path ) === $path ) {
return true;
}
if ( strlen( $path ) === 0 || '.' === $path[0] ) {
return false;
}
// Windows allows absolute paths like this.
if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
return true;
}
// A path starting with / or \ is absolute; anything else is relative.
return ( '/' === $path[0] || '\\' === $path[0] );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |

