timostamm/text-truncation

Installs: 880

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/timostamm/text-truncation

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

This package is auto-updated.

Last update: 2025-10-05 21:51:50 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 );