fork(3) download
  1. <?php
  2. $needles = array('one', 'of', 'here', 'Another');
  3. $text = 'Start of sentence one. This is a wordmatch one two three four! Another, sentence here.';
  4.  
  5. if (preg_match_all('/.+?[!.]\s*/', $text, $match)) {
  6. $hits = array_filter($match[0], function ($sentence) use($needles) {
  7. foreach ($needles as $needle) {
  8. if (false !== strpos($sentence, $needle)) {
  9. return true;
  10. }
  11. }
  12.  
  13. return false;
  14. });
  15.  
  16. print_r($hits);
  17. }
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Start of sentence one. 
    [1] => This is a wordmatch one two three four! 
    [2] => Another, sentence here.
)