0
function stripSingleEndedTag($content, $allowed = array()){
(array)$allowed;
$singletags = array('<meta>','<img>','<input>','<hr>','<br>','<link>','<isindex>','<base>','<meta>','<nextid>','<bork>');

$stripthese = arrayfilterout ($singletags, $allowed);
$stripthese = str_replace(array('<','>'),'',$stripthese);

$pattern = '/<('. implode('|', $stripthese) .')[^>]+\>/i'; 

$content = preg_replace($pattern, "", $content);
return $content;
}

私がここに持っているもの<bork />は、「bork」の後と「>」の前に何らかの文字がある場合に限り、シングルエンドのタグを取り除きます。 <bork >削除され<bork/>ますが、削除されません<bork>

ところで、使えませんstrip_tags()

4

1 に答える 1

2

以下を使用できます。

$pattern = '/\<('. implode('|', $stripthese) .')[^>]*\>/i';

元の回答:

andを削除しますが、 <bork />andは削除し<bork/>ませんか?<bork><bork >

あなたが望むのは次のようです:

$pattern = '/<('. implode('|', $stripthese) .').*\\\>/i';

更新:貪欲な一致の修正:

$pattern = '/<('. implode('|', $stripthese) .').*?\\\>/i';
$pattern = '/<('. implode('|', $stripthese) .')[^>]*\\\>/i';
于 2013-04-12T03:50:28.503 に答える