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.

// @link
$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 );


apply( string $haystack, string $needle)
Highlight the $needle in the $haystack


There are a number of hooks available to further modify the behavior of \SearchWP\Highlighter: