normalize_whitespace

Normalize EOL characters and strip duplicate whitespace.

Description

(string) normalize_whitespace( (string) $str ); 

Returns (string)

The normalized string.

Parameters (1)

0. $str (string)
The string to normalize.

Usage

  1. if ( !function_exists( 'normalize_whitespace' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // The string to normalize. 
  5. $str = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = normalize_whitespace($str); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function normalize_whitespace( $str ) { 
  2. $str = trim( $str ); 
  3. $str = str_replace( "\r", "\n", $str ); 
  4. $str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str ); 
  5. return $str;