fork download
  1. <?php
  2.  
  3. function highlight_term($text, $words)
  4. {
  5. return preg_replace('~\b(?:' . implode("|", $words) . ')\b~u', '<b>$0</b>', $text);
  6. }
  7.  
  8. $str = "ह ट इ ड यन भ भ और द";
  9.  
  10. echo highlight_term($str, ['और','भ']);
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
ह ट इ ड यन <b>भ</b> <b>भ</b> <b>और</b> द