Charactor conversion help needed!

Hai folks,

i am in need of converting “John” to Unicode UCS-2 (also know as UTF16 i think) Encording.

i tried this function.

function Str2Utf16($string) {
  $string = iconv("ISO-8859-1", "UTF-16", $string);
  return $string;

output : þÿJohn
expecting : 004a006f0068006e (obtained from an online converter)

Please help!!

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

You can also mb_convert_encoding()

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!!!

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).
	   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 :rolleyes:

Hai folks,

This worked!

$strTerm = '7302';
echo mb_convert_encoding(bin2hex(mb_convert_encoding($strTerm, 'UCS-2', 'auto')), 'UCS-2', 'auto');

output : 0037003300300032

Thank you.

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.


Hai buddy,
we are using sms gateway. so all unicode messages (multi lang) should encoded to the UCS-2 Standed as per thiere documentation

  • load that pdf and search for the text UCS :slight_smile:

Thank you!

(after some digging around maybe its because of Javascript Encoding, maybe they use node.js?)

hmm not sure about that :smiley: