キーワードのハイライト


/ Published in: PHP
Save to your folder(s)

キーワードをハイライトするようにHTMLでおきかえる。


Copy this code and paste it in your HTML
  1. function highlight($sString, $aWords) {
  2. if (!is_array ($aWords) || empty ($aWords) || !is_string ($sString)) {
  3. return false;
  4. }
  5.  
  6. $sWords = implode ('|', $aWords);
  7. return preg_replace ('@\b('.$sWords.')\b@si', '<strong style="background-color:yellow">$1</strong>', $sString);
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.