Skip to main content
Participant
July 23, 2008
Question

utf-8 to hexadecimal

  • July 23, 2008
  • 5 replies
  • 694 views
I have a online form which require user to input text (which may contains asian language). the charset of the application is utf-8

How could we convert the received text into their hexadecimal values?

pls kindly advise
    This topic has been closed for replies.

    5 replies

    dynasonAuthor
    Participant
    July 25, 2008
    I have tried hexToString function but does not display characters correctly.

    For example, I used the code from cf.marc to convert an Asian character to hex (value is 4e2d).

    After using hexToString, the character is not correctly.

    Pls kindly advise.
    Inspiring
    July 24, 2008
    dynason wrote:
    > How could we convert the received text into their hexadecimal values?

    why?
    Inspiring
    July 24, 2008
    Hi,

    You can try this UDF.

    http://cflib.org/udf/hexToString
    dynasonAuthor
    Participant
    July 24, 2008
    Thank you very much.

    Pls kindly also advise how to convert hex back to utf8.
    July 23, 2008
    <cfif structKeyExists(form,"asian_string")>
    <cfset strLen = len(form['asian_string'])>
    <cfset hex = arrayNew(1)>

    <cfloop from="1" to="#strLen#" index="i">
    <cfset current_char = mid(form['asian_string'],i,1)>
    <cfset arrayAppend(hex,formatBaseN(asc(current_char),16))>
    </cfloop>

    <cfdump var="#hex#">
    </cfif>

    <form action="" method="post">
    <input type="text" name="asian_string" />
    <input type="submit" />
    </form>