– Common Function Library Project

abbreviate(string, len)

Last updated September 06, 2005



Version: 3 | Requires: CF5 | Library: StrLib

Similar to the MaxLength UDF, but designed for outputting abbreviated lengths of HTML code (e.g. in list tables). Strips all tags, and makes sure any abbreviation is done to the last space within the given length. Also appends a properly escaped ellipsis character to the returned string.

Return Values:
Returns a string.


#abbreviate("<p>This bit of HTML copy is going to get <em>real</em> chopped up!</p>", 40)#


Name Description Required
string String to use. Yes
len Length to use. Yes

Full UDF Source:

 * Abbreviates a given string to roughly the given length, stripping any tags, making sure the ending doesn't chop a word in two, and adding an ellipsis character at the end.
 * Fix by Patrick McElhaney
 * v3 by Ken Fricklas, takes care of too many spaces in text.
 * @param string      String to use. (Required)
 * @param len      Length to use. (Required)
 * @return Returns a string. 
 * @author Gyrus ( 
 * @version 3, September 6, 2005 
function abbreviate(string,len) {
    var newString = REReplace(string, "<[^>]*>", " ", "ALL");
    var lastSpace = 0;
    newString = REReplace(newString, " \s*", " ", "ALL");
    if (len(newString) gt len) {
        newString = left(newString, len-2);
        lastSpace = find(" ", reverse(newString));
        lastSpace = len(newString) - lastSpace;
        newString = left(newString, lastSpace) & "  &##8230;";
    return newString;


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson