私はいくつかの tekst エンリッチメントを含む文字列を持っています。文字列には zo there<b>
と<em>
いくつかの他の html タグがあります。もちろん、ユーザーは<script>
または他のものを文字列に入れることもできますが、それはあなたが望むものではありません。<
and>
を<
andに置き換えたいのですが、andは置き換え>
ません。<b>
<em>
3 に答える
1
ネガティブな先読みが必要なようです。
$escaped = preg_replace("(</?(?!(?:b|em)\b))","<",$raw);
それ自体には意味がないので>
、逃げる必要はないことに注意してください。>
于 2013-02-28T20:03:43.070 に答える
1
これをテストする
$notecomments=" <b> <em> <sf> <script>";
$output=preg_replace_callback(array("#<(.*?)>#"),function($matches){
switch($matches[1]){
case 'b':
case 'em':
return $matches[0];
break;
default:
return "<".$matches[1].">";
}
},' '.$notecomments.' ');
print_r($output);
出力:
<b> <em> <sf> <script>
于 2013-02-28T20:08:49.217 に答える
0
おそらく、 strip_tagsはこれに適しています:
echo strip_tags($text, '<b><em>');
于 2013-02-28T20:10:34.350 に答える