https://github.com/writecrow/highlighter
Highlights words/phrases per specified parameters
https://github.com/writecrow/highlighter
highlight natural-language-processing php-library
Last synced: about 2 months ago
JSON representation
Highlights words/phrases per specified parameters
- Host: GitHub
- URL: https://github.com/writecrow/highlighter
- Owner: writecrow
- License: mit
- Created: 2019-02-27T04:38:43.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-02-13T15:19:16.000Z (4 months ago)
- Last Synced: 2025-04-11T14:10:31.308Z (about 2 months ago)
- Topics: highlight, natural-language-processing, php-library
- Language: PHP
- Homepage: https://highlighter.markfullmer.com/
- Size: 40 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Excerpt Highlighter
A PHP library for creating a highlighted excerpt a provided list of tokens in a provided text string.
## Basic usage in an application
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;`)```php
print HighlightExcerpt::highlight('Round the rugged rock,' ['the']);
// Will print 'Round the rugged rock'print HighlightExcerpt::highlight('Round the rugged rock,' ['the', 'rock']);
// Will print 'Round the rugged rock'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````
## Advanced behaviors
The excerpt highlighter will:
- Default to case-insensitive highlighting for a word (e.g., `'the'`)
- Become case-sensitive if the token is wrapped in double quotes (e.g. `'"The"'`)
- Not highlight partial word matched (e.g., `'the'` will not highlight `therefore`)
- Given multiple tokens passed to be highlighted, will create shorter, concatenated excerpts from the text which overall try to honor the length parameter specified (see below)
- Produce excerpts that start/end on word boundaries### Length
Pass a 3rd parameter, an integer, to the function to specify the desired length of the excerpt.```php
print HighlightExcerpt::highlight('Round the rugged rock,' ['the'], 300);
// Would limit the excerpt to 300 characters
```