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.

Return

String. The processed string.

Usage

wp_strip_all_tags( $string, $remove_breaks );
$string(string) (required)
String containing HTML tags
$remove_breaks(true/false)
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

<?php
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