wordpress / latest / functions / normalize_whitespace.html

normalize_whitespace( string $str ): string

Normalizes EOL characters and strips duplicate whitespace.

Parameters

$str string Required
The string to normalize.

Return

string The normalized string.

Source

File: wp-includes/formatting.php. View all references

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

Used By

Used By Description

Changelog

Version Description
2.7.0 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/normalize_whitespace