fork(1) download
  1. <?php
  2. $keywords = array('dog', 'cat', 'cow');
  3. $text = 'I own two dogs, four cats, and twenty cows.';
  4. $regexp = '/\b(' . implode('|', $keywords) . ').*?\b/';
  5. echo preg_replace($regexp, '<b>$0</b>', $text);
  6.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
I own two <b>dogs</b>, four <b>cats</b>, and twenty <b>cows</b>.