Truncate
extends Twig_Extension
in package
A Tiwg extension that truncates text while preservice HTML tags.
Based on http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/
Table of Contents
- getFilters() : mixed
- getName() : mixed
- truncate() : string
- Truncates a string up to a number of characters while preserving whole words and HTML tags
Methods
getFilters()
public
getFilters() : mixed
Return values
mixed —getName()
public
getName() : mixed
Return values
mixed —truncate()
Truncates a string up to a number of characters while preserving whole words and HTML tags
public
truncate(string $text[, int $length = 100 ][, string $ending = '...' ][, bool $exact = false ][, bool $considerHtml = true ]) : string
Parameters
- $text : string
-
String to truncate.
- $length : int = 100
-
Length of returned string, including ellipsis.
- $ending : string = '...'
-
Ending to be appended to the trimmed string.
- $exact : bool = false
-
If false, $text will not be cut mid-word
- $considerHtml : bool = true
-
If true, HTML tags would be handled correctly
Return values
string —Truncated string.