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.
Return
(string) The normalized string.
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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.7.0 | Introduced. |