WP_CLI\Utils

normalize_path()WP-CLI 1.0

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 one. Ensures upper-case drive letters on Windows systems.

No Hooks.

Return

String. Normalized path.

Usage

normalize_path( $path );
$path(string) (required)
Path to normalize.

normalize_path() code WP-CLI 2.8.0-alpha

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