wp_normalize_path( string $path )
Normalize a filesystem path.
Description 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 Parameters
- $path
-
(string) (Required) Path to normalize.
Return Return
(string) Normalized path.
Source Source
File: wp-includes/functions.php
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; }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
4.9.7 | Allows for PHP file wrappers. |
4.5.0 | Allows for Windows network shares. |
4.4.0 | Ensures upper-case drive letters on Windows systems. |
3.9.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example
A Simple example to normalize the theme include path
Expand full source codeCollapse full source code
print_r($bS_incl_path);
showsUsing this function:
Without this function:
On a Windows server.