在php中strip_tags() 函数,可以剥去 HTML、XML 以及 PHP 的标签。
用法:
strip_tags(string,allow)
后面的allow是可选的。填入的话表示什么标签被允许。
附,php使用strip_tags清除所有标记。
string strip_tags(string str);
函数strip_tags可去掉字符串中包含的任何 HTML 及 PHP 的标记字符串。若是字符串的 HTML 及 PHP 标签原来就有错,例如少了大于的符号,则也会返回错误。
string strip_tags ( string str [, string allowable_tags] ) 返回一个去除了HTML标签的字符串;可以使用第二个参数来设置不需要删除的标签。
例如:
<?php strip_tags($str, "<a>"); //保留$str中的a标签 ?>
问题1,strip_tags如何保留多个HTML标签?
只需要将多个标签用空格分隔后写到strip_tags的第二个参数中,代码:
strip_tags($str, "<p> <b>");
问题2,php删除html标记中的特定标签的方法?
代码:
<?php
/**
* 删除html标记中的特定标签
* edit www.jb200.com
*/
function strip_selected_tags($text, $tags = array())
{
        $args = func_get_args();
        $text = array_shift($args);
        $tags = func_num_args() > 2 ? array_diff($args,array($text)) : (array)$tags;
        foreach ($tags as $tag){
            if( preg_match_all( '/<'.$tag.'[^>]*>([^<]*)</'.$tag.'>/iu', $text, $found) ){
                $text = str_replace($found[0],$found[1],$text);
            }
        }
        return preg_replace( '/(<('.join('|',$tags).')( | |.)*/>)/iu', '', $text);
    }
$str = "[url="]123[/url]";
echo strip_selected_tags($str,array('b'));
?>