wp_strip_all_tags

Properly strip all HTML tags including script and style.

Description

(string) wp_strip_all_tags( (string) $string, (constant) $remove_breaks = false ); 

This differs from strip_tags() because it removes the contents of the' )' will return something. wp_strip_all_tags will return ''

Returns (string)

The processed string.

Parameters (2)

0. $string (string)
String containing HTML tags
1. $remove_breaks — Optional. (constant) => false
Whether to remove left over line breaks and white space chars

Usage

  1. if ( !function_exists( 'wp_strip_all_tags' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // String containing HTML tags 
  5. $string = ''; 
  6.  
  7. // Optional. Whether to remove left over line breaks and white space chars 
  8. $remove_breaks = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_strip_all_tags($string, $remove_breaks); 
  12.  

Defined (1)

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

/wp-includes/formatting.php  
  1. function wp_strip_all_tags($string, $remove_breaks = false) { 
  2. $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string ); 
  3. $string = strip_tags($string); 
  4.  
  5. if ( $remove_breaks ) 
  6. $string = preg_replace('/[\r\n\t ]+/', ' ', $string); 
  7.  
  8. return trim( $string );