\SearchWP\Highlighter
\SearchWP\Highlighter は文字列内の文字列をハイライトできます。
基本的な使い方
\SearchWP\Highlighter のすべての使用には、$haystack と $needle の 2 つのパラメータが必要です。$haystack 内の $needle は <mark class="searchwp-highlight"/> 要素でラップされます。
This file contains hidden or 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 ); |
メソッド
apply( string $haystack, string $needle)$haystack内の$needleをハイライトします
フック
\SearchWP\Highlighter の動作をさらに変更するために、いくつかのフックが利用可能です。

