fork(1) download
  1. <?php
  2.  
  3. $myStr = "some words that are cool";
  4. $myWords = array('words', 'cool');
  5. $myWordString = join('|', $myWords);
  6.  
  7. $myRegex = "/(^|[\s.,])(" . $myWordString . ")([\s.,]|$)/iu";
  8.  
  9. print("Regexp is: " . $myRegex . "\n");
  10. preg_match_all($myRegex, $myStr, $myRes);
  11. var_dump($myRes[2]);
  12.  
  13. ?>
  14.  
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
Regexp is: /(^|[\s.,])(words|cool)([\s.,]|$)/iu
array(2) {
  [0]=>
  string(5) "words"
  [1]=>
  string(4) "cool"
}