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

后端 未结 5 1774
北海茫月
北海茫月 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:10

    I am using it for XML tags string.

    Ahmad MaaropCJ, Zaharah Ibrahim, Prasad Sandosham, Jeffrey Tan, Alizatul Khair FCJJ\r\n';
     $patterns = array('/\bCJ\b/', '/\bJCA\b/','/\bJJCA\b/','/\bPCA\b/', '/\bCJM\b/', '/\bCJSS\b/', '/\bFCJ\b/', '/\bFCJJ\b/', '/\bJ\b/','/\bH\b/', '/\bPK\b/','/\bJC\b/', '/\bHMP\b/', '/\bHHMP\b/', '/\bHMR\b/', '/\bHHMR\b/');
     $replacements = array('CJ', 'JCA','JJCA','PCA', 'CJM', 'CJSS', 'FCJ', 'FCJJ', 'J','H', 'PK','JC', 'HMP', 'HHMP', 'HMR', 'HHMR');
    
       
    
    
      $string = preg_replace($patterns,$replacements,$xmlString);
      
      
      echo $string;
    // Ahmad Maarop CJ, Zaharah Ibrahim, Prasad Sandosham, Jeffrey Tan, Alizatul Khair FCJJ\r\n ◀
    
      
    ?>

提交回复
热议问题