PHP preg_replace three times with three different patterns? right or wrong?

后端 未结 5 1812
北海茫月
北海茫月 2020-12-30 07:43

A simple question: Is this the best way to do it?

$pattern1 = \"regexp1\";
$pattern2 = \"regexp2\";
$pattern3 = \"regexp3\";

$content = preg_replace($patter         


        
5条回答
  •  盖世英雄少女心
    2020-12-30 08:24

    To do multiple searches in a single preg_replace() call, use an array of patterns. You can still pass a single replacement, this is what's matched by all three patterns is replaced with:

    $content = preg_replace(array($pattern1, $pattern2, $pattern3), '', $content);
    

提交回复
热议问题