Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created April 12, 2022 14:49
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 searchwpgists/7e6e836b054af619ea345a78ec84068e to your computer and use it in GitHub Desktop.
Save searchwpgists/7e6e836b054af619ea345a78ec84068e to your computer and use it in GitHub Desktop.
Basic usage of SearchWP's Highlighter class
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment