• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / wp_normalize_path() – Normalize a filesystem path.

You appear to be a bot. Output may be restricted

Description

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.

Usage

$string = wp_normalize_path( $path );

Parameters

$path
( string ) required – Path to normalize.

Returns

string Normalized path.

Source

File name: wordpress/wp-includes/functions.php
Lines:

1 to 22 of 22
function wp_normalize_path( $path ) {
  $wrapper = '';

  if ( wp_is_stream( $path ) ) {
    list( $wrapper, $path ) = explode( '://', $path, 2 );

    $wrapper .= '://';
  }

  // Standardise all paths to use '/'.
  $path = str_replace( '\\', '/', $path );

  // Replace multiple slashes down to a singular, allowing for network shares having two slashes.
  $path = preg_replace( '|(?<=.)/+|', '/', $path );

  // Windows paths should uppercase the drive letter.
  if ( ':' === substr( $path, 1, 1 ) ) {
    $path = ucfirst( $path );
  }

  return $wrapper . $path;
}
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 2nd April 2020

Primary Sidebar

Information

Function name: wp_normalize_path
Plugin ref: WordPress
Version: 5.7.1
Sourcefile: wp-includes/functions.php
File ref: wp-includes/functions.php
Deprecated?: No
API Letters: N,P,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites