Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

kannel - Classic ASP - How to convert a UTF-8 string to UTF-16?

I know there is already have post: Classic ASP - How to convert a UTF-8 string to UCS-2?

But my situation another.
I want convert UTF-8 to UCS-2BE.
For example this text in UTF-8 "Мухтарам Мизоч" convert to this "CEB0@0<? 87>G".

For example in PHP i can use ready function iconv("utf-8","ucs-2be","Мухтарам Мизоч");
But in classical ASP can't find any solution.
This solution need for send Unicode SMS text via Kannel.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So sick of answering this question, but I feel impelled to as you have made a common assumption that many make when it comes to encoding in ASP, PHP or whatever language you are using.

In web development encoding is intrinsically linked to

The source encoding you use to save the web page

Just looking at the comments under the iconv reference made me laugh and sad at the same time because there are so many people out there who don't understand this topic.

Take for example your PHP snippet

iconv("utf-8","ucs-2be","Мухтарам Мизоч");

This will work providing the following is true

  • The page author saved the file using UTF-8 encoding (Most modern editors have this option in some shape or form).
  • The client Internet Browser knows it should be handling the page as UTF-8 either via a meta tag in the HTML,

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    

    or by specifying a HTTP Content-Type Header


In terms of Classic ASP it is the same you need to;

  • Make sure the page is saved as UTF-8 encoding, this includes any #include files that are dependencies.

  • Tell IIS that your pages are UTF-8 by specifying this pre-processing instruction at the very top of the page (must be the first line).

    <%@Language="VBScript" CodePage = 65001 %>
    
  • Tell the browser what encoding you are using

    <%
    'Tell server to send all strings back to the client as UTF-8
    'while also setting the charset in the HTTP Content Type header.
    Responce.CodePage = 65001
    Response.ContentType = "html/text"
    Response.Charset = "UTF-8"
    %>
    

UPDATE:

Neither UCS-2 (UTF-16 LE) or UCS-2BE (UTF-16 BE) are supported by Classic ASP, specifying either CodePage (1200 or 1201) will result in;

ASP 0203 - Invalid CodePage Value

After reading a bit about Kannel it does appear as though you can control the character set you send to the SMS gateway, I would recommend you try to send it using UTF-8.

Links


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...