yarri/keywords-highlighter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yarri/keywords-highlighter

最新稳定版本:v0.1.5

Composer 安装命令:

composer require yarri/keywords-highlighter

包简介

Highlights keywords (typically a search query) in a HTML string

README 文档

README

Build Status Downloads

Highlights keywords (typically a search query) in a HTML string.

Basic usage

$html_text = '
  <h1>The truth about pizza and beer</h1>

  <p>
    Beer and pizza.
    It might be one of the most obvious food pairings on the planet...
  </p>
';

$highlighter = new \Yarri\KeywordsHighlighter();

echo $highlighter->highlight($html_text,"pizza beer");

//  <h1>The truth about <mark>pizza</mark> and <mark>beer</mark></h1>
//
//  <p>
//    <mark>Beer</mark> and <mark>pizza</mark>.
//    It might be one of the most obvious food pairings on the planet...
//  </p>

The default tag for highlighting can be overwritten in options of the constructor.

$highlighter = new \Yarri\KeywordsHighlighter([
  "opening_tag" => '<span class="highlight">',
  "closing_tag" => '</span>',
]);

echo $highlighter->highlight($html_text,"pizza beer");

//  <h1>The truth about <span class="highlight">pizza</span> and <span class="highlight">beer</span></h1>
//
//  <p>
//    <span class="highlight">Beer</span> and <span class="highlight">pizza</span>.
//    It might be one of the most obvious food pairings on the planet...
//  </p>

KeywordsHighlighter doesn't highlight something inside a html tag.

$html_text = '
  <h1>The truth about the H1 element</h1>
';

$highlighter = new \Yarri\KeywordsHighlighter();

echo $highlighter->highlight($html_text,"h1");

// <h1>The truth about the <mark>H1</mark> element</h1>

Installation

composer require yarri/keywords-highlighter

Testing

composer update --dev
cd test
../vendor/bin/run_unit_tests

统计信息

  • 总下载量: 22.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-18