class JHtmlString

HTML helper class for rendering manipulated strings.

Methods

static  string
truncate( string $text, integer $length, boolean $noSplit = true, boolean $allowHtml = true)

Truncates text blocks over the specified character limit and closes all open HTML tags. The method will optionally not truncate an individual word, it will find the first space that is within the limit and truncate at that point. This method is UTF-8 safe.

static  string
truncateComplex( string $html, integer $maxLength, boolean $noSplit = true)

Method to extend the truncate method to more complex situations

static  string
abridge( string $text, integer $length = 50, integer $intro = 30)

Abridges text strings over the specified character limit. The behavior will insert an ellipsis into the text replacing a section of variable size to ensure the string does not exceed the defined maximum length. This method is UTF-8 safe.

Details

static string truncate( string $text, integer $length, boolean $noSplit = true, boolean $allowHtml = true)

Truncates text blocks over the specified character limit and closes all open HTML tags. The method will optionally not truncate an individual word, it will find the first space that is within the limit and truncate at that point. This method is UTF-8 safe.

Parameters

string $text The text to truncate.
integer $length The maximum length of the text.
boolean $noSplit Don't split a word if that is where the cutoff occurs (default: true).
boolean $allowHtml Allow HTML tags in the output, and close any open tags (default: true).

Return Value

string The truncated text.

static string truncateComplex( string $html, integer $maxLength, boolean $noSplit = true)

Method to extend the truncate method to more complex situations

The goal is to get the proper length plain text string with as much of the html intact as possible with all tags properly closed.

Parameters

string $html The content of the introtext to be truncated
integer $maxLength The maximum number of characters to render
boolean $noSplit Don't split a word if that is where the cutoff occurs (default: true).

Return Value

string The truncated string. If the string is truncated an ellipsis (...) will be appended.

static string abridge( string $text, integer $length = 50, integer $intro = 30)

Abridges text strings over the specified character limit. The behavior will insert an ellipsis into the text replacing a section of variable size to ensure the string does not exceed the defined maximum length. This method is UTF-8 safe.

For example, it transforms "Really long title" to "Really...title".

Note that this method does not scan for HTML tags so will potentially break them.

Parameters

string $text The text to abridge.
integer $length The maximum length of the text (default is 50).
integer $intro The maximum length of the intro text (default is 30).

Return Value

string The abridged text.