A PHP library for creating a highlighted excerpt a provided list of tokens in a provided text string.
The included index.php
file contains a generation form demo.
Make your code aware of the Highlighter class via your favorite method
(e.g., use writecrow\Highlighter\HighlightExcerpt;
)
print HighlightExcerpt::highlight('Round the rugged rock,' ['the']);
// Will print 'Round <mark>the</mark> rugged rock'
print HighlightExcerpt::highlight('Round the rugged rock,' ['the', 'rock']);
// Will print 'Round <mark>the</mark> rugged <mark>rock</mark>'
print HighlightExcerpt::highlight('Round the rugged rock,' ['ro', '"round"']);
// Will print 'Round the rugged rock', since `ro` is present,
// but only a word partial,
// and `round` is present, but double-quotes indicate case-sensitivity
// so `round` != `Round`
The excerpt highlighter will:
'the'
)'"The"'
)'the'
will not highlight therefore
)Pass a 3rd parameter, an integer, to the function to specify the desired length of the excerpt.
print HighlightExcerpt::highlight('Round the rugged rock,' ['the'], 300);
// Would limit the excerpt to 300 characters