Question

Is there any ColdFusion function similar to mb_convert_encoding in PHP?

I need to convert following PHP code to ColdFusion:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<?php
    $str = $_GET["brand"]; //%93%FA%8EY%8E%A9%93%AE%8E%D4
    $str = mb_convert_encoding($str,'UTF-8',"SJIS");
    echo $str; //日産自動車
?>

In short, is there any inbuilt function in cold-fusion that converts the character encoding of string str to 'UTF-8' from 'SJIS'?

Was it helpful?

Solution

Update:

By default CF uses UTF-8 to decode URL variables. "To decode .. URL variables in any other encoding ... you must use the setEncoding function."

<cfscript>
   setEncoding("URL", "shift_jis");
   writeDump(URL.brand); // result 日�Y自動車 
</cfscript>

When you have questions like this, the first place to look is in the Functions by Category view of the documentation. All of the functions are descriptively named. You can usually figure out the function you need by its name alone. If you look over the String Functions section, you will find two functions that (combined) should do the trick:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top