返回介绍

wp_normalize_path()

发布于 2017-09-11 12:32:07 字数 2939 浏览 960 评论 0 收藏 0

wp_normalize_path( string $path )

Normalize a filesystem path.


description

On windows systems, replaces backslashes with forward slashes and forces upper-case drive letters. Allows for two leading slashes for Windows network shares, but ensures that all other duplicate slashes are reduced to a single.


参数

$path

(string) (Required) Path to normalize.


返回值

(string) Normalized path.


源代码

File: wp-includes/functions.php

function wp_normalize_path( $path ) {
	$path = str_replace( '\\', '/', $path );
	$path = preg_replace( '|(?<=.)/+|', '/', $path );
	if ( ':' === substr( $path, 1, 1 ) ) {
		$path = ucfirst( $path );
	}
	return $path;
}

更新日志

Versiondescription
4.5.0Allows for Windows network shares.
4.4.0Ensures upper-case drive letters on Windows systems.
3.9.0Introduced.

相关函数

Used By

  • wp-includes/link-template.php: plugins_url()
  • wp-includes/plugin.php: plugin_basename()
  • wp-includes/plugin.php: wp_register_plugin_realpath()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    A Simple example to normalize the theme include path

    
        $bS_incl_path = get_template_directory() . '/inc';
    
        /**
         * Define theme include path
         * 
         * Normalize the include path to be safe on windows hosts
         * @return string Normalized path
         * require min WordPress version 3.9
         * @since boot_Strap 1.0.1
         * 
         */
    
         if(function_exists('wp_normalize_path')){
             
            $bS_incl_path = wp_normalize_path($bS_incl_path);
         }
        
        define('THM_INC', $bS_incl_path);
    
        require_once (THM_INC. '/wp_bootstrap_navwalker.php');   
    

    print_r($bS_incl_path); shows

    Using this function:

    
    C:/xampp/htdocs/boot_strap/wp-content/themes/boot_Strap/inc
    

    Without this function:

    
    C:\xampp\htdocs\boot_strap/wp-content/themes/boot_Strap/inc
    

    On a Windows server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文