\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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
$needle
in the$haystack
Hooks
There are a number of hooks available to further modify the behavior of \SearchWP\Highlighter
: