writecrow/highlighter

根据指定参数高亮显示单词或短语

2.0.1 2022-10-29 20:29 UTC

This package is auto-updated.

Last update: 2024-08-28 03:13:44 UTC


README

A PHP 库,用于在提供的文本字符串中创建一个高亮显示的摘录,该摘录包含提供的标记列表。

在应用程序中的基本用法

包含的 index.php 文件包含一个生成表单演示。

通过您喜欢的任何方法使您的代码了解 Highlighter 类(例如,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'
  • 如果标记用双引号括起来,则变为大小写敏感(例如,'"The"'
  • 不会高亮显示部分单词匹配(例如,'the' 不会高亮显示 therefore
  • 给定要高亮显示的多个标记,将尝试从文本中创建更短的、连接的摘录,同时总体上尝试遵守指定的长度参数(见下文)
  • 摘录从单词边界开始/结束

长度

向函数传递第三个参数,一个整数,以指定所需摘录的长度。

print HighlightExcerpt::highlight('Round the rugged rock,' ['the'], 300);
// Would limit the excerpt to 300 characters