XMF Cookbook
Search…
Highlighting Content
There are times when you may want to highlight certain words within your module page. One common use is to guide the user to occurrences of search terms in the display body. For this example, we assume you have an array of terms to highlight in $words, and some text (HTML is fine) in $body.
1
$pre = '<span class=”highlight”>';
2
$post = '</span>';
3
\Xmf\Highlighter::apply($words, $body, $pre, $post);
Copied!
Each occurrence of $words in $body will be surrounded by $pre and $post. If you do not specify the $pre and $post arguments, the terms will be surrounded by <strong> and </strong> tags.
Last modified 3yr ago
Copy link