fork(2) download
  1. <?php
  2.  
  3. $words = array('General', 'Director','President','General Manager','Constituency Aid','Data Input Clerk','Front Desk Clerk','General Director','Planning Officer');
  4. usort($words, function($a, $b) {
  5. return strlen($b) - strlen($a);
  6. });
  7. $pattern= '/\b(?:' . implode("|", $words) . ')\b/i';
  8. $s = "Meet our new General Director!";
  9. echo preg_replace($pattern, "<a href='#'>\$0</a>", $s);
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
Meet our new <a href='#'>General Director</a>!