fork(1) download
  1. <?php
  2.  
  3. $internal_message = 'Hey, this is awesome!';
  4.  
  5. $words = array(
  6. 'wesome' => 'wful',
  7. 'wful' => 'wesome',
  8. 'this' => 'that',
  9. 'that' => 'this'
  10. );
  11. $rx = '~(?:' . implode("|", array_keys($words)) . ')\b~';
  12. echo "$rx\n";
  13. $message = preg_replace_callback($rx, function($m) use ($words) {
  14. return isset($words[$m[0]]) ? $words[$m[0]] : $m[0];
  15. }, $internal_message);
  16. echo $message;
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
~(?:wesome|wful|this|that)\b~
Hey, that is awful!