- 论坛徽章:
- 0
|
原帖由 alexru 于 2008-1-1 00:24 发表 ![]()
查查strip打头的函数吧
不然用正则
strip的那个,是删除所有,并保留部分设定的。
<?php
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).')(\n|\r|.)*\/>)/iu', '', $text);
}
$str = "123";
echo strip_selected_tags($str,array('b'));
?> |
|
|