Oihana PHP

normalizePath.php

Table of Contents

Functions

normalizePath()  : string
Normalizes the given file system path by replacing backslashes with slashes.

Functions

normalizePath()

Normalizes the given file system path by replacing backslashes with slashes.

normalizePath(string $path) : string

This function is useful to unify path separators across different operating systems. It ensures all directory separators are forward slashes (/), making the path suitable for consistent comparison, storage, or manipulation.

It does not resolve relative components like . or .., nor does it canonicalize or validate the path against the filesystem.

Parameters
$path : string

The path to normalize. Can contain mixed or inconsistent separators.

Tags
example
normalizePath('C:\\Users\\myuser\\Documents');
// Returns: 'C:/Users/myuser/Documents'

normalizePath('/var/www/html');
// Returns: '/var/www/html'
see
realpath()

For actual filesystem canonicalization.

author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

The normalized path with all backslashes (\) replaced by forward slashes (/).


        
On this page

Search results