\SearchWP\Highlighter
Table of Contents
\SearchWP\Highlighter can highlight strings within strings.
Basic Usage
All usage of \SearchWP\Highlighter requires two parameters, a $haystack and a $needle. A $needle within a $haystack will be wrapped in a <mark class="searchwp-highlight"/> element.
| <?php | |
| // @link https://searchwp.com/documentation/classes/searchwp-highlighter/ | |
| $highlighter = new \SearchWP\Highlighter(); | |
| $haystack = 'The best coffee you can find!'; | |
| $needle = 'coffee'; | |
| // Output: | |
| // The best <mark class="searchwp-highlight">coffee</mark> you can find! | |
| echo $highlighter->apply( $haystack, $needle ); |
Methods
apply( string $haystack, string $needle)- Highlight the
$needlein the$haystack
Hooks
There are a number of hooks available to further modify the behavior of \SearchWP\Highlighter:

