normalize_whitespace( string $str ): string

In this article

Normalizes EOL characters and strips duplicate whitespace.

Parameters

$strstringrequired
The string to normalize.

Return

string The normalized string.

Source

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

Changelog

VersionDescription
2.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.