fork download
  1. <?php
  2.  
  3. $str = "The man drove in his car.Then <strong>the man walked to the boat.</strong>";
  4. $keywords = array('boat','car');
  5. $p = implode('|', array_map('preg_quote', $keywords));
  6. $result = preg_replace("#<strong>.*?<\/strong>(*SKIP)(*FAIL)|\b($p)\b#i", "gokart", $str);
  7. echo $result;
Success #stdin #stdout 0.02s 24192KB
stdin
Standard input is empty
stdout
The man drove in his gokart.Then <strong>the man walked to the boat.</strong>