wp_spaces_regexp

Returns the regexp for common whitespace characters.

Description

(string) wp_spaces_regexp(); 

By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp. This is designed to replace the PCRE \s sequence. In ticket #22692, that sequence was found to be unreliable due to random inclusion of the A0 byte.

Returns (string)

The spaces regexp.


Usage

  1. if ( !function_exists( 'wp_spaces_regexp' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_spaces_regexp(); 
  7.  

Defined (1)

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

/wp-includes/formatting.php  
  1. function wp_spaces_regexp() { 
  2. static $spaces = ''; 
  3.  
  4. if ( empty( $spaces ) ) { 
  5. /** 
  6. * Filters the regexp for common whitespace characters. 
  7. * This string is substituted for the \s sequence as needed in regular 
  8. * expressions. For websites not written in English, different characters 
  9. * may represent whitespace. For websites not encoded in UTF-8, the 0xC2 0xA0 
  10. * sequence may not be in use. 
  11. * @since 4.0.0 
  12. * @param string $spaces Regexp pattern for matching common whitespace characters. 
  13. */ 
  14. $spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0| ' ); 
  15.  
  16. return $spaces;