2017 © Pedro Peláez
 

library textsnippet

Create a snippet of text highlighting a given string

image

swisnl/textsnippet

Create a snippet of text highlighting a given string

  • Saturday, July 29, 2017
  • by swisnl
  • Repository
  • 5 Watchers
  • 4 Stars
  • 85 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 21 % Grown

The README.md

SWIS Text Snippet

Easy and fast way to create a snippet of text, for example for a search result. It will try and highlight the given words and give you the relevant text around it., (*1)

Build Status Latest Stable Version License Buy us a tree, (*2)

Installation

Just use composer to install the package. Or download and include the TextSnipet.php file., (*3)

composer require swisnl/textsnippet, (*4)

Examples

Some examples based on a 3 paragraph long Lorum ipsum text., (*5)

Basic usage

$snippet = new TextSnippet()
$snippet->createSnippet('Lorem', $lorumIpsum);

Will result in:, (*6)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. ... Etiam bibendum lorem nec tempus sollicitudin. ... Sed in dapibus lorem. ... Nunc turpis ipsum, bibendum quis sodales sed, ullamcorper et lorem. Donec et metus hendrerit, interdum elit ut, dignissim dui., (*7)

Setting highlight html

You can set the tags surrounding the highlighted text. The %word% tag is required., (*8)

$snippet = new TextSnippet()
$snippet->setHighlightTemplate('<strong>%word%</strong>')

Setting min and max words

Setting min and maxwords tells the class to try and keep the number of words between the min and max., (*9)

// Defaults
$minWords = 30;
$maxWords = 100;

Setting min and max words., (*10)

$snippet = new TextSnippet()
$snippet->setMinWords(10);
$snippet->setMaxWords(30);

There is a known issue if you set min and max very close to eachother. It might not find the correct set of words/sentences to get exactly between the small gap., (*11)

Licence

The MIT License (MIT). Please see License File for more information., (*12)

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats., (*13)

SWIS :heart: Open Source

SWIS is a web agency from Leiden, the Netherlands. We love working with open source software., (*14)

The Versions

29/07 2017

dev-master

9999999-dev

Create a snippet of text highlighting a given string

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Vincent Kleijnendorst

29/07 2017

2.0.0

2.0.0.0

Create a snippet of text highlighting a given string

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Vincent Kleijnendorst

29/07 2017

1.0.0

1.0.0.0

Create a snippet of text highlighting a given string

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Vincent Kleijnendorst