If you develop web applications in coldfusion in a foreign language like spanish, french or german you have to get rid of those horrible question marks where characters with accents supposed to be. If foreign characters with accents or not properly coded they will be shown as a question mark, for example España will be shown as Espa?a.
I will explain how to get rid of all the accents in your urls, from your database, or when you do a cfhttp get operation. And how to display them correctly at your webpage with coldfusionMX, all samples or crossbrowser checked.
First of all, add the following lines of code to your Application.cfm file, to show all characters correctly:
Application.cfm:
<cfcontent type="text/html; charset=iso-8859-15">
<cfset setEncoding("URL", "iso-8859-15")>
<cfset setEncoding("Form", "iso-8859-15")>
this will show all the form and url variables in french,german and spanish correctly.
iso-8859-15 includes the Euro sign as well (instead of iso-8859-1).
If you want to use a coldfusion variable in your url (searchengines are loving that!!) you need to get rid of the accents before you can use them in a url, below I will you show my solution (works perfect).
Example:
<!-------------- first url encode your variable ----------------->
<cfset no_accents = urlencodedformat("TéléViseurs")>
<!-------------- replace simply all the characters with accents to a character without accent (it is just an example, not all the accents are included.----------------->
<cfset no_accents = rereplacenocase(no_accents,"(%E0|%E1|%E2|%E3)","a","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%E8|%E9|%EA|%EB)","e","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%EC|%ED|%EE|%EF)","i","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%F2|%F3|%F4|%F5)","o","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%F9|%FA|%FB)","u","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%F1)","n","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%B5)","u","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%E7)","c","all")>
<cfset no_accents = rereplacenocase(no_accents,"(%AE|%3F|%C2%AE)","","all")>
<cfset no_accents = urldecode(no_accents)>
<cfset urltobuild = "http://www.mywebsite.com/#lcase(replace(no_accents,' ','-','all'))#.html">
final url is:
http://www.mywebsite.com/televiseurs.html
with just adding this few lines of code to your application you will get a perfect webpage with or without accents.
Best,
Harry Kuperus
Reacties