Posted By

jrobinsonc on 10/21/11


Tagged

highlight


Versions (?)

Highlight Search Words


 / Published in: PHP
 

  1. function highlight($word, $subject) {
  2.  
  3. $split_subject = explode(" ", $subject);
  4. $split_word = explode(" ", $word);
  5.  
  6. foreach ($split_subject as $k => $v){
  7. foreach ($split_word as $k2 => $v2){
  8. if($v2 == $v){
  9.  
  10. $split_subject[$k] = "<span class='highlight'>".$v."</span>";
  11.  
  12. }
  13. }
  14. }
  15.  
  16. return implode(' ', $split_subject);
  17. }

Report this snippet  

You need to login to post a comment.