path_is_absolute
函数
path_is_absolute ( $path )
- 参数
-
-
(string)
$path
File path.- Required: 是
-
(string)
- 返回值
-
- (bool) True if path is absolute, false is not absolute.
- 定义位置
-
-
wp-includes/functions.php
, line 2087
-
wp-includes/functions.php
- 引入
- 2.5.0
- 弃用
- –
测试一个给定的文件系统路径是否是绝对的。
例如,’/foo/bar’,或’c:windows’。
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;
}
// Normalized Windows paths for local filesystem and network shares (forward slashes).
if ( preg_match( '#(^[a-zA-Z]+:/|^//[w!@#$%^()-'{}.~]{1,15})#', $path ) ) {
return true;
}
// A path starting with / or is absolute; anything else is relative.
return ( '/' === $path[0] || '' === $path[0] );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。