wppaste
WordPress

wp_normalize_path( string $path ): string

Since
3.9.0, 4.4.0, 4.5.0, 4.9.7
Source
wp-includes/functions.php:2185
Normalizes 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.

Parameters

$pathstring
Path to normalize.

Return

string
Normalized path.

Uses · 1

Used by · 24

Show all 24

Source

function wp_normalize_path( $path ) {	$wrapper = ''; 	if ( wp_is_stream( $path ) ) {		list( $wrapper, $path ) = explode( '://', $path, 2 ); 		$wrapper .= '://';	} 	// Standardize 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;}

History

Introduced in 3.9.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

4.9.7
Allows for PHP file wrappers.from the docblock
4.5.0
Allows for Windows network shares.from the docblock
4.4.0
Ensures upper-case drive letters on Windows systems.from the docblock
3.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.