API16

JHtmlString/abridge: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== 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 do...
 
m preparing for archive only
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
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.
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.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JHtmlString/abridge|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JHtmlString/abridge}}
 
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 59: Line 57:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JHtmlString/abridge|Edit See Also]]<nowiki>]</nowiki>
<! removed transcluded page call, red link never existed >
</span>
{{SeeAlso:JHtmlString/abridge}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=abridge
  category=abridge
  category=JHtmlString
  category=JHtmlString
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API16]]

Latest revision as of 01:47, 25 March 2017

Description

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

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

string The abridged text.

Defined in

libraries/joomla/html/html/string.php

Importing

jimport( 'joomla.html.html.string' );

Source Body

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

Code Examples