wp_strip_all_tags() – Properly strip all HTML tags including script and style

You appear to be a bot. Output may be restricted

Description

Properly strips all HTML tags including script and style

This differs from strip_tags() because it removes the contents of the <script> and <style> tags. E.g. strip_tags( '<script>something</script>' ) will return 'something'. wp_strip_all_tags will return ''

Usage

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

Parameters

$string
( string ) required – String containing HTML tags
$remove_breaks
( bool ) optional – Optional. Whether to remove left over line breaks and white space chars

Returns

string The processed string.

Source

File name: wordpress/wp-includes/formatting.php
Lines:

1 to 10 of 10
function wp_strip_all_tags( $string, $remove_breaks = false ) {
  $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
  $string = strip_tags( $string );

  if ( $remove_breaks ) {
    $string = preg_replace( '/[\r\n\t ]+/', ' ', $string );
  }

  return trim( $string );
}
 

 View on GitHub View on Trac