ap_highlight_words( string $text, string $words )
Description #
Highlight matching words.
Parameters #
- $textstring (Required) String.
- $wordsstring (Required) Words need to highlight.
Source #
File: includes/functions.php
function ap_highlight_words( $text, $words ) {
$words = explode( ' ', $words );
foreach ( $words as $word ) {
// Quote the text for regex.
$word = preg_quote( $word, '/' );
// Highlight the words.
$text = preg_replace( "/\b($word)\b/i", '<span class="highlight_word">\1</span>', $text );
}
return $text;
}
Expand full source code Collapse full source code View on GitHub: includes/functions.php:486
Add your comment