2011-02-14 62 views

回答

2

一个简单的正则表达式的复合搜索将工作(如果这仍然是你以前的问题):

$html = 
preg_replace("#</?(font|strike|marquee|blink|del)[^>]*>#i", "", $html); 
+0

请解释这部分:[^>] * – texai 2011-02-23 22:06:02

1

试试这个功能发表LWC上php.net - http://www.php.net/manual/en/function.strip-tags.php#96483

<?php 
function strip_only($str, $tags, $stripContent = false) { 
    $content = ''; 
    if(!is_array($tags)) { 
     $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags)); 
     if(end($tags) == '') array_pop($tags); 
    } 
    foreach($tags as $tag) { 
     if ($stripContent) 
      $content = '(.+</'.$tag.'[^>]*>|)'; 
     $str = preg_replace('#</?'.$tag.'[^>]*>'.$content.'#is', '', $str); 
    } 
    return $str; 
} 

$str = '<font color="red">red</font> text'; 
$tags = 'font'; 
$a = strip_only($str, $tags); // red text 
$b = strip_only($str, $tags, true); // text 
?>