0

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.

Community
  • 1
  • 1
  • Take a look at this answer, like you the OP was trying to send to an SMS Provider - [Answer to convert utf-8 to iso-8859-1 in classic asp](http://stackoverflow.com/a/17680939/692942). – user692942 Sep 03 '14 at 13:10
  • The difference is your passing in `UTF-8` and want to output `UTF-16` (supersedes `UCS-2`) the process is identical. – user692942 Sep 03 '14 at 13:17
  • I've dug into this a bit more as I'm not familiar with the Kannel SMS Gateway. What version are you using? Looking at the [user guide](http://www.kannel.org/download/1.4.3/userguide-1.4.3/userguide.html) suggests that [by default the `coding` parameter is set to 7 bits](http://www.kannel.org/download/1.4.3/userguide-1.4.3/userguide.html#AEN4322) when using the `sendsms` cgi script so you should be able to send `UTF-8` is it possible to update your question and add some code that shows you trying to send the message to the `sendsms` cgi script? – user692942 Sep 04 '14 at 13:58

2 Answers2

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

user692942
  • 16,398
  • 7
  • 76
  • 175
  • I think doing it right, but i'm get in UTF-16 "믯킿톜톃톅킂톰킀킰₼鳐룐럐뻐蟑" in PHP i get "CEB0@0<� 87>G". May be UTF-16 and UCS-2be not same? – Farhod Hojiev Sep 03 '14 at 20:34
  • 1
    You maybe right, as `UTF-16` does not supersede `UCS-2BE` (big endian) it's supersedes `UCS-2`. What's more neither are supported in IIS / Classic ASP, if you try to set them you will get `ASP 0203 - Invalid CodePage Value`. You need to configure Kannel to send using `UTF-8` which from what I have read it is more then capable of doing. – user692942 Sep 04 '14 at 12:42
  • 1
    Yes, i'm decide my problem with setting in Kannel "coding=UTF-8". – Farhod Hojiev Sep 06 '14 at 20:58
0

in kannel.conf in section SMSC add alt-charset = UCS-2 (or UCS-2BE) thats enough. Kannel well send to smsc in this charset.

BDaler
  • 1
  • 3