Strip out all Html, Php, Js tags by wp_strip_all_tags WordPress Function

wp_strip_all_tags is a built in wordpress function. Which is used to strip out tags from the given strings. It is a modified function of PHP strip_tags function or an extended version. strip_tags function is used to remove HTML and PHP tags from strings. And wp_strip_all_tags does two more things than it. It also remove JavaScript and inline style. Moreover wp_strip_all_tags can remove line breaks into white spaces.

wp_strip_all_tags function is located in /wp-includes/formatting.php on line 2771 on WP version 3.0.3.

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

    if ( $remove_breaks )
        $string = preg_replace('/[rnt ]+/', ' ', $string);

    return trim($string);

You can use this function in your php file for striping HTML, PHP, JS, CSS tags.

$raw_text = '<div>Test paragraph.</div><script type="text/javascript">...</script><style type="text/css"></style><!-- Comment -->';
$striped_text = wp_strip_all_tags($raw_text, true);

// will return - “Test paragraph.”

Arguments Reference:
– First parameter is the (string) you want to strip codes from.
– Second parameter is (boolean), if set to true, line breaks will be also removed, default is false which prevents line break removal.