afridy
August 5, 2012, 11:14am
1
Hai folks,
i am in need of converting “John” to Unicode UCS-2 (also know as UTF16 i think) Encording.
i tried this function.
<?php
function Str2Utf16($string) {
$string = iconv("ISO-8859-1", "UTF-16", $string);
return $string;
}
?>
output : þÿJohn
expecting : 004a006f0068006e (obtained from an online converter)
Please help!!
afridy
August 5, 2012, 5:21pm
2
Hi folks
i found the code page for UCS-2, Now my plan is to create a function to manually convert each alpha numeric charactors individullay
http://www.columbia.edu/kermit/ucs2.html
pavels
August 6, 2012, 6:16pm
3
afridy
August 8, 2012, 7:59am
4
WOW, Glad to know about this function pavels,
as per the php documentation, this functions supports UCS-2, this would be a great thing. let me try out and come back to you!!!
afridy
August 8, 2012, 9:48am
5
function convert($str){
$str = mb_convert_encoding($str, "UCS-2","auto");
return $str;
}
$empno_ucs2=convert($empno); // $empno = 7302
echo $empno_ucs2; // out put 7302 (showing no changes).
$empno_ucs2=implode(unpack('C*',$empno_ucs2));
echo $empno_ucs2; //055051048050
Problem : when you convert 7302 using an online UCS-2 Converter, the above out put 055051048050 is wrong.
it must be 0037003300300032
Any idea
afridy
August 8, 2012, 10:44am
6
Hai folks,
This worked!
<?php
$strTerm = '7302';
echo mb_convert_encoding(bin2hex(mb_convert_encoding($strTerm, 'UCS-2', 'auto')), 'UCS-2', 'auto');
?>
output : 0037003300300032
Thank you.
Cups
August 8, 2012, 11:18am
7
Hi, @afridy ;, despite your conducting a conversation largely with yourself on this issue, perhaps you can explain to me (us) why it is important for you to encode data as UCS-2. I would like to understand as it not something I have come across before.
Thanks
afridy
August 8, 2012, 11:22am
8
Cups:
Hi, @afridy ;, despite your conducting a conversation largely with yourself on this issue, perhaps you can explain to me (us) why it is important for you to encode data as UCS-2. I would like to understand as it not something I have come across before.
Thanks
Hai buddy,
we are using clickatell.com sms gateway. so all unicode messages (multi lang) should encoded to the UCS-2 Standed as per thiere documentation http://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf
load that pdf and search for the text UCS
Cups
August 8, 2012, 5:03pm
9
Thank you!
(after some digging around maybe its because of Javascript Encoding , maybe they use node.js?)