wp_normalize_path()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_normalize_path( string $path ): string
Описание
В системах Windows заменяет обратные слэши прямыми и приводит буквы дисков к верхнему регистру.
Допускает два ведущих слэша для сетевых ресурсов Windows, но гарантирует, что все остальные дублирующиеся слэши сокращаются до одного.
Оригинал (английский)
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.
Параметры
$path
string
обязательный
Возвращаемое значение
string
Исходный код
wp-includes/functions.php:2187
function wp_normalize_path( $path ): string {
$path = (string) $path;
static $cache = array();
if ( isset( $cache[ $path ] ) ) {
return $cache[ $path ];
}
$original_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 = (string) preg_replace( '|(?<=.)/+|', '/', $path );
// Windows paths should uppercase the drive letter.
if ( ':' === substr( $path, 1, 1 ) ) {
$path = ucfirst( $path );
}
$cache[ $original_path ] = $wrapper . $path;
return $cache[ $original_path ];
}
История изменений
| Версия | Описание |
|---|---|
| 7.0.0 | Uses a static cache to store normalized paths. |
| 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. |

