Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active November 11, 2020 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/7c30c421a677dc0beb6f1f0324cedb09 to your computer and use it in GitHub Desktop.
Save jchristopher/7c30c421a677dc0beb6f1f0324cedb09 to your computer and use it in GitHub Desktop.
Basic usage of SearchWP's Highlighter class
<?php
$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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment