Link to home
Start Free TrialLog in
Avatar of JimV_ATL
JimV_ATL

asked on

LSEuroCurrencyFormat & CFFile problem

LSEuroCurrencyFormat appears to work perfectly for me when during typical conditions when I display the results using <cfoutput>.  However, when I write the results to a file using CFFile, it displays a "? " instead of the expected Euro Symbol.

Note the following:

1)  I'm using CFMX.  I have run both updaters.
2)  LSCurrencyFormat works fine both when outputed using CFOutput as well as using CFFile.

Here is sample code which reproduces my error:

<!---  You'll want to change this for your environment --->
<cfset absolute_file_root = "c:\webs\sandbox\">

<cfsavecontent variable="results">
<cfoutput>
<table>
<cfloop index="idx" list="English (UK),English (US),Dutch (Standard),French (Standard),German (Standard),Italian (Standard)">
<cfset temp = setlocale(idx)>
<tr><td>#idx#</td><td>#LSEuroCurrencyFormat(1000.00)#</td><td>#LSCurrencyFormat(1000.00)#</td></tr>
</cfloop>
</table>
</cfoutput>
</cfsavecontent>

<!---  Results display as expected here. --->
<cfoutput>
#results#
</cfoutput>

<!---  Next two lines create unique file name --->
<cfset timestamp = DateFormat(now(),"yyyymmdd") & TimeFormat(now(),"HHmmss")>
<cfset filename= "test_" & timestamp & ".htm">

<!---  Results don't display as expected here. --->
<cffile action="WRITE" file="#absolute_file_root#Temp\#filename#" output="#results#" addnewline="No">


Avatar of weeezl
weeezl

It seems like CF is writing the actual character to screen instead of using the HTML equivalent. This seems to be what is causing the problem on the write.

I fixed it by doing a replace and writing the proper HTML.

<cfset absolute_file_root = "c:\webs\sandbox\">

<cfsavecontent variable="results">
<cfoutput>
<table>
<cfloop index="idx" list="English (UK),English (US),Dutch (Standard),French (Standard),German (Standard),Italian (Standard)">
<cfset temp = setlocale(idx)>
<tr><td>#idx#</td><td>#LSEuroCurrencyFormat(1000.00)#</td><td>#LSCurrencyFormat(1000.00)#</td></tr>
</cfloop>
</table>
</cfoutput>
</cfsavecontent>

<!--- Replace Euro Symbol with HTML --->
<cfset results=replace(results,'€','&##8364;','all')>

<!---  Results display as expected here. --->

<cfoutput>
#results#
</cfoutput>

<!---  Next two lines create unique file name --->
<cfset timestamp = DateFormat(now(),"yyyymmdd") & TimeFormat(now(),"HHmmss")>
<cfset filename= "test_" & timestamp & ".htm">

<!---  Results don't display as expected here. --->
<cffile action="WRITE" file="#absolute_file_root#Temp\#filename#" output="#results#" addnewline="No">
Avatar of JimV_ATL

ASKER

Thanks for your suggestion!

I'm hoping for more of a direct solution rather than a work-around.

Jim
One more comment:

When I view the output from the CFOutput it looks like:

<table>
<tr><td>English (UK)</td><td>£1,000.00</td><td>£1,000.00</td></tr>
<tr><td>English (US)</td><td>$1,000.00</td><td>$1,000.00</td></tr>
<tr><td>Dutch (Standard)</td><td>€ 1.000,00</td><td>fl 1.000,00</td></tr>
<tr><td>French (Standard)</td><td>1 000,00 €</td><td>1 000,00 F</td></tr>
<tr><td>German (Standard)</td><td>1.000,00 €</td><td>1.000,00 DM</td></tr>
<tr><td>Italian (Standard)</td><td>€ 1.000,00</td><td>L. 1.000</td></tr>
</table>

When I view the output from the CFFile it looks like:



<table>
<tr><td>English (UK)</td><td>£1,000.00</td><td>£1,000.00</td></tr>
<tr><td>English (US)</td><td>$1,000.00</td><td>$1,000.00</td></tr>
<tr><td>Dutch (Standard)</td><td>? 1.000,00</td><td>fl 1.000,00</td></tr>
<tr><td>French (Standard)</td><td>1 000,00 ?</td><td>1 000,00 F</td></tr>
<tr><td>German (Standard)</td><td>1.000,00 ?</td><td>1.000,00 DM</td></tr>
<tr><td>Italian (Standard)</td><td>? 1.000,00</td><td>L. 1.000</td></tr>
</table>

Hmmm...looks like EE must have escaped the Euro symbol in the above.  
The article is over a year old and refers to different symptoms on CF5. The common denominator seems to be that LSEuroCurrencyFormat is not among the better tested CF functions, so it is easy for me to believe that this is a bug and requires a work-around.  

Thanks for the link!  If I don't get the answer I'm looking for by Monday morning, then the points are yours.

I got the solution I was looking for.

1) Added <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> to the <head> portion of the html output. (Actually, I had to make the entire output valid html, prior to that point it was just the table code.)
2) Explicitly added charset="UTF-8" to the cffile.

Here is the resulting code that worked:

<!--- You'll want to change this for your environment --->
<cfset absolute_file_root = "c:\webs\sandbox\">

<cfsavecontent variable="results">
<cfoutput>
<table>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<cfloop index="idx" list="English (UK),English (US),Dutch (Standard),French (Standard),German (Standard),Italian (Standard)">
<cfset temp = setlocale(idx)>
<tr><td>#idx#</td><td>#LSEuroCurrencyFormat(1000.00)#</td><td>#LSCurrencyFormat(1000.00)#</td></tr>
</cfloop>
</body>
</html>
</table>
</cfoutput>

</cfsavecontent>

<!--- Results display as expected here. --->
<cfoutput>
#results#
</cfoutput>

<!--- Next two lines create unique file name --->
<cfset timestamp = DateFormat(now(),"yyyymmdd") & TimeFormat(now(),"HHmmss")>
<cfset filename= "test_" & timestamp & ".htm">

<!--- Results don't display as expected here. --->
<cffile action="WRITE" file="#absolute_file_root#Temp\#filename#" output="#results#" addnewline="No" charset="UTF-8">
I'm going ask that my answer be the answer to this question (for Knowledge Base purposes).  I've opened a second question, so you can have the ponits.

https://www.experts-exchange.com/questions/20534110/Points-for-weeezl.html
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial