CFLib.org – Common Function Library Project

magicQuote(txt)

Last updated May 1, 2006

author

Keith Gaughan

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Accepts a single string and converts any straight typewriter quotes into their corresponding curly typographer's quotes to give a better visual appearence. Note, however, that this code assumes that the text passed in is plain text and not HTML.

Return Values:
Returns a string.

Example:

<cfoutput>#MagicQuote("""It's working?""")#</cfoutput>

Parameters:

Name Description Required
txt Text to format. Yes

Full UDF Source:

/**
 * Cleanly converts typewriter quotes to typographer's quotes.
 * 
 * @param txt 	 Text to format. (Required)
 * @return Returns a string. 
 * @author Keith Gaughan (kmgaughan@eircom.net) 
 * @version 1, May 1, 2006 
 */
function magicQuote(txt) {
    // Left quotes
    txt = REReplace(txt, "(^|[ " & Chr(9) & Chr(10) & Chr(13) & "'])""", "\1&##8220;", "ALL");
    txt = REReplace(txt, "(^|[ " & Chr(9) & Chr(10) & Chr(13) & "]|&##8220;)'",  "\1&##8216;", "ALL");

    // Right quotes
    txt = Replace(txt, """",        "&##8221;",  "ALL");
    txt = Replace(txt, "'&##8220;", "'&##8221;", "ALL");
    txt = Replace(txt, "'",         "&##8217;",  "ALL");

    return txt;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson