Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Smart Quotes Causing Havoc 1

Status
Not open for further replies.

DMAN3021

Programmer
Joined
Aug 20, 2002
Messages
40
Location
CA
Alright,

I've got this smart quotes problem, where when I, or users of my web app, copy a text from word to a text area and submit it, quotes produced by MS Word are turned into ugly symbols.

I've tried using the replace=() function, I've tried using a cf script to replace characters above 128, but nothing is working!

Please, if anyone knows of a way to fix this problem, I've run out of ideas...
 
PHP is our friend today

I tried googling for "smartquotes" "cold fusion" and I got a forum where a php programmer was having a similar problem.

Code:
$quotes = array(chr(145), chr(146), chr(147), chr(148));
$xhquotes = array("'","'", """, """);

$clean_text= str_replace($quotes,$xhquotes,$file_text);

The good news is here's how to write that in CF:

Code:
<cfset newstring = replacelist(string,"#chr(145)#,#chr(146)#,#chr(147)#,#chr(148)#","&#39;,&#39;,&#34;,&#34;")>

A direct code import would look like this...

Code:
<cfset quotes = ListToArray("#chr(145)#,#chr(146)#,#chr(147)#,#chr(148)#")>
<cfset xhquotes=ListToArray("&#39;,&#39;,&#34;,&#34;")>
<cfset clean_text=replacelist(string,ArrayToList(quotes),ArrayToList(xhquotes))>

Which of course converts to an array and back to a list which isn't useful. I was just demonstrating because someone asked me the other day why CF needs lists AND arrays. I've gotta say, they're both great for their own reasons.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
That's pretty slick, webmigit! [smarty]



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Hey,

Thanks for your help Webmigit. The code you wrote is stuff that I had tried before, and still I was unable to get it to work. However, I just found out that this problem might have something to do with character sets.

So I tried it out, adding the following lines to the application.cfm file that I created earlier in my web-application's directory.

Code:
<cfset setEncoding("form","ISO-8859-1")>

<cfcontent type="text/html; charset=ISO-8859-1">

It was difficult to find but now works like a charm. Thanks for you help!

Dan...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top