timostamm/text-truncation

dev-master 2017-10-03 16:11 UTC

This package is auto-updated.

Last update: 2024-05-05 18:22:40 UTC


README

This utility truncates plain text to a maximum length. It recognizes paragraphs, sentences and words and uses them to cut the text in a smart way.

Example

// Setup a truncation for a maximum string length of 370 characters.
// Use the Paragraph-Strategy, which tries to find a paragraph 
// within the first 370 characters, and falls back to a sentence or  
// a word.
$t = new Truncation( 370, Truncation::STRATEGY_PARAGRAPH );

// Apply the truncation 
$txt = $t->truncate( $x );