View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > SetEncoding PreviousNext

SetEncoding

Sets the character encoding (character set) of Form and URL scope variable values; used when the character encoding of the input to a form, or the character encoding of a URL, is not in UTF-8 encoding.

None

International functions, System functions

SetEncoding(scope_name,charset)

GetEncoding, cfcontent, cfprocessingdirective, URLDecode, URLEncodedFormat

ColdFusion MX: Added this function.

Parameter

Description

scope_name

  • url
  • form

charset

The character encoding in which text in the scope variables is encoded. The following list includes commonly used values:

  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16

Use this function when the character encoding of the input to a form or the character encoding of a URL is not in UTF-8 encoding. For example, Traditional Chinese characters are often in Big5 encoding. Before using URL or Form variables, call this function (typically, in the Application.cfm page) to set the encoding and avoid interpreting the characters of the variables incorrectly.

For more information on character encoding, see the following web pages:

<!--- This example sends and interprets the contents of two fields as
      big5 encoded text. Note that the form fields are received as URL variables
      because the form uses the GET method. --->
<cfcontent type="text/html; charset=big5">
<form action='#cgi.script_name#' method='get'>
<input name='xxx' type='text'>
<input name='yyy' type='text'>
<input type="Submit" value="Submit">
</form>

<cfif IsDefined("URL.xxx")>
<cfscript>
   SetEncoding("url", "big5"); 
   WriteOutput("URL.XXX is " & URL.xxx & "<br>"); 
   WriteOutput("URL.YYY is " & URL.yyy & "<br>");
    theEncoding = GetEncoding("URL");
    WriteOutput("The URL variables were decoded using '" &
theEncoding & "' encoding."); </cfscript> </cfif>

Contents > CFML Reference > ColdFusion Functions > SetEncoding PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


No screen name said on Oct 14, 2005 at 7:36 AM :
WARNING: It seems that this will return the URL and FORM variables back to their original states from in the HTTP request. That means if there were any in-code changes to URL or FORM variables (like a CFPARAM) prior to the point this fucntion is called, those changes will be lost. This does not apply if there were no URL or FORM variables in the original HTTP request, in which case the in-code changes to those scopes will be safely retained.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa79.htm