JHtmlString/abridge
From Joomla! Documentation
< API16:JHtmlString
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
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.
<! removed transcluded page call, red link never existed >
Syntax[edit]
abridge($text, $length=50, $intro=30)
Parameter Name | Default Value | Description |
---|---|---|
$text | $text The text to abridge. | |
$length | 50 | $length The maximum length of the text. |
$intro | 30 | $intro The maximum length of the intro text. |
Returns[edit]
string The abridged text.
Defined in[edit]
libraries/joomla/html/html/string.php
Importing[edit]
jimport( 'joomla.html.html.string' );
Source Body[edit]
function abridge($text, $length = 50, $intro = 30)
{
// Abridge the item text if it is too long.
if (JString::strlen($text) > $length) {
// Determine the remaining text length.
$remainder = $length - ($intro + 3);
// Extract the beginning and ending text sections.
$beg = JString::substr($text, 0, $intro);
$end = JString::substr($text, JString::strlen($text)-$remainder);
// Build the resulting string.
$text = $beg.'...'.$end;
}
return $text;
}
<! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]