fork download
  1. <?php
  2. $str='a a a b b b c c c';
  3. $regex = array('/\b(a)\b\s*/', '/\b(b)\b\s*/', '/\b(c)\b\s*/');
  4. $repl = array('{\1}', '<\1>', '{\1}');
  5.  
  6. $nstr = preg_replace($regex, $repl, $str);
  7. echo "$nstr\n";
  8. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
{a}{a}{a}<b><b><b>{c}{c}{c}