normalize_whitespace() WordPress Function

The normalize_whitespace() function is used to remove any extra whitespace from a string. This includes spaces, tabs, and newlines. This function is useful for cleaning up user-entered data, such as when a user is typing in a textarea.

normalize_whitespace( string $str ) #

Normalizes EOL characters and strips duplicate whitespace.


Parameters

$str

(string)(Required)The string to normalize.


Top ↑

Return

(string) The normalized string.


Top ↑

Source

File: wp-includes/formatting.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;
}


Top ↑

Changelog

Changelog
VersionDescription
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More