I ha开发者_运维百科ve a line of coldfusion code that includes an cfm file encoded with the utf-8 charset and saves it to a variable. The problem I am having is that there is no way to specify a charset in cfinclude and the resulting variable does not seem to be reading utf-8 correctly so any non ascii characters are rendered incorrectly.
<cfsavecontent variable="content">
<cfinclude template="test.cfm">
</cfsavecontent>
<cfoutput>#content#</cfoutput>
If I use cffile this is not a problem because I can specify a chaset, but the file is not parsed for coldfusion variables.
<cfset path = expandPath(".") & "\test.html">
<cffile action="read" file="#path#" variable="content" charset="utf-8">
<cfoutput>#content#</cfoutput>
So my question - Is there a way to load a parsed coldfusion file into a variable while honoring a specific charset?
I don't know if this will work or not, but the only thing I can think of is to put a
<cfprocessingdirective pageencoding="utf-8" />
tag at the very top of the code being included (test.cfm). This instructs CF to use a specific encoding when compiling the code.
I think you need the cfprocessingdirective in both the included file and the master file.
精彩评论