问题
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.
回答1:
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
Sending arabic SMS in kannel (This question is about sending arabic SMS using Java to Kannel but the information is relevant).
Unicode on Windows XP (Although aimed at Windows XP the codepage information is still relevant).
回答2:
in kannel.conf in section SMSC add alt-charset = UCS-2 (or UCS-2BE) thats enough. Kannel well send to smsc in this charset.
来源:https://stackoverflow.com/questions/25642816/classic-asp-how-to-convert-a-utf-8-string-to-utf-16