WordPress at a glance

wp_strip_all_tags() WP 1.0

Properly strip 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 ''

Is the basis for: sanitize_text_field()
✈ 1 time = 0.000037s = very fast | 50000 times = 0.93s = very fast

No Hooks.


String. The processed string.


wp_strip_all_tags( $string, $remove_breaks );
$string(string) (required)
String containing HTML tags
Whether to remove left over line breaks and white space chars
Default: false

Code of wp strip all tags: wp-includes/formatting.php VER 5.0.3

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 );

Related Functions

From tag: esc_ (clean validate sanitize)

More from category: Sanitizing, Escaping

No comments
    Hello, !     Log In . Register