WordPress at Your Fingertips

normalize_whitespace() WP 1.0

Normalize EOL characters and strip duplicate whitespace.

1 time — 0.000123 sec (fast) | 50000 times — 0.04 sec (speed of light)

No Hooks.

Return

String. The normalized string.

Usage

normalize_whitespace( $str );
$str(string) (required)
The string to normalize.

Changelog

Since 2.7.0 Introduced.

Code of normalize_whitespace() WP 5.7.2

<?php
function normalize_whitespace( $str ) {
	$str = trim( $str );
	$str = str_replace( "\r", "\n", $str );
	$str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str );
	return $str;
}

From category: Formatting

No comments
    Log In