This is an improvement to the built in strip_tags plugin that supports an allowable_tags argument to match the functionality of its php equivalent. It supports full backwards compatibility, so you don't have to worry about dropping it in and messing up your existing templates.

Two examples of same as always:

{$var|strip_tags}
{$var|strip_tags:false}

An example of php style strip_tags (will leave <b> and <p>):

{$var|strip_tags:'<b><p>'}

An example of both old and new functionality together:

{$var|strip_tags:false:'<b><p>'}

Here is the code:

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty strip_tags modifier plugin
 *
 * Type:    modifier

 * Name:    strip_tags

 * Purpose: strip html tags from text
 * @link    http://www.smarty.net/manual/en/language.modifier.strip.tags.php
 *          strip_tags (Smarty online manual)
 *
 * @author  Monte Ohrt <monte at ohrt dot com>
 * @author  Jordon Mears <jordoncm at gmail dot com>
 *
 * @version 2.0
 *
 * @param   string
 * @param   boolean optional
 * @param   string optional
 * @return  string
 */
function smarty_modifier_strip_tags($string) {
    switch(func_num_args()) {
        case 1:
            $replace_with_space = true;
            break;
        case 2:
            $arg = func_get_arg(1);
            if($arg === 1 || $arg === true || $arg === '1' || $arg === 'true') {
                // for full legacy support || $arg === 'false' should be included
                $replace_with_space = true;
                $allowable_tags = '';
            } elseif($arg === 0 || $arg === false || $arg === '0' || $arg === 'false') {
                // for full legacy support || $arg === 'false' should be removed
                $replace_with_space = false;
                $allowable_tags = '';
            } else {
                $replace_with_space = true;
                $allowable_tags = $arg;
            }
            break;
        case 3:
            $replace_with_space = func_get_arg(1);
            $allowable_tags = func_get_arg(2);
            break;
    }

    if($replace_with_space) {
        $string = preg_replace('!(<[^>]*?>)!', '$1 ', $string);
    }

    $string = strip_tags($string, $allowable_tags);

    if($replace_with_space) {
        $string = preg_replace('!(<[^>]*?>) !', '$1', $string);
    }

    return $string;
}

/* vim: set expandtab: */

?>