talideon.com

You’ve got to change the world and use this chance to be heard!

March 17, 2006 at 8:18PM Converting typewriter quotes to proper typographer’s quotes

Here’s how to do it in a nice clean way that works in everything from ColdFusion 5 and on:

function MagicQuote(txt) {
    var prefix = "(^|[ " & Chr(9) & Chr(10) & Chr(13);

    // Left quotes
    txt = REReplace(txt, prefix & "'])""",        "\1&##8220;", "ALL");
    txt = REReplace(txt, prefix & "]|&##8220;)'", "\1&##8216;", "ALL");

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

    return txt;
}
Technorati Search Technorati Search Irish Bloggers

Comments

No comments.

Post a comment

All form information is optional, but it’s a good idea to fill in your name and email address if you want me to take your comment seriously.

Spammers, don’t bother posting crap down here. The site is set up so that legitimate search engines (Google, for instance) won’t index pages with comments on them. Posting crud here only means you’re wasting my time and patience. Shoo!

Real names, please. Please include!
Won’t be displayed. Please include!
Displayed, if present.