CFLib.org – Common Function Library Project

HTMLTrans(string)

Last updated August 28, 2003

author

Oblio

Version: 2 | Requires: CF5 | Library: StrLib

Description:
This function is intended to obfuscate strings on a page. It converts characters to their ASCII decimal equivalent, and outputs the concatenated result in place of the original. This is particularly useful for protecting email addresses from harvesters (or at least until they figure it out). Best of all, you can still use href="mailto:#HTMLTrans(example)#".

Return Values:
Returns a string.

Example:

<cfset example="name@example.com">

<cfoutput>#HTMLTrans(example)#</cfoutput>

Parameters:

Name Description Required
string String to format. Yes

Full UDF Source:

/**
 * Converts the characters in a string to encoded special characters.
 * Rewritten by Raymond Camden
 * 
 * @param string      String to format. (Required)
 * @return Returns a string. 
 * @author Oblio (oleitch@locustcreek.com) 
 * @version 2, August 28, 2003 
 */
function HTMLTrans(string) {
    var slen = len(string);
    var encoded = "";

    while (slen) {
        encoded = encoded & "&##" & Asc(left(string,1)) & ";";
        string = mid(string,2,slen-1);
        slen=len(string);
    }
    return encoded;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson