^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助,如果有代码出错,请联系站长解决
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数wp_normalize_path()用法示例

wp_normalize_path( string $path )

Normalize a filesystem path.


描述

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$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;
}

更新日志

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

相关函数

Used By

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

  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.

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈