StringHelper
HTML helper class for rendering manipulated strings.
| since |
1.6 |
|---|---|
| package |
Joomla CMS |
Methods
abridge
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.
abridge( text, length = 50, intro = 30) :
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.
| since |
1.6 |
|---|
Arguments
- text
stringThe text to abridge.- length
intThe maximum length of the text (default is 50).- intro
intThe maximum length of the intro text (default is 30).
Response
stringThe abridged text.
truncate
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.
truncate( text, length, noSplit = true, allowHtml = true) :
| since |
1.6 |
|---|
Arguments
- text
stringThe text to truncate.- length
intThe maximum length of the text.- noSplit
boolDon't split a word if that is where the cutoff occurs (default: true).- allowHtml
boolAllow HTML tags in the output, and close any open tags (default: true).
Response
stringThe truncated text.
truncateComplex
Method to extend the truncate method to more complex situations
truncateComplex( html, maxLength, noSplit = true) :
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.
| note |
If a maximum length of 3 or less is selected and the text has more than that number of characters an ellipsis will be displayed. This method will not create valid HTML from malformed HTML. |
|---|---|
| since |
3.1 |
Arguments
- html
stringThe content of the introtext to be truncated- maxLength
intThe maximum number of characters to render- noSplit
boolDon't split a word if that is where the cutoff occurs (default: true).
Response
stringThe truncated string. If the string is truncated an ellipsis
(...) will be appended.