SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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.

    Code:
    <?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!!

  2. #2
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Member
    Join Date
    May 2012
    Posts
    6
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can also mb_convert_encoding() http://www.php.net/manual/en/functio...t-encoding.php

  4. #4
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pavels View Post
    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!!!

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function convert($str){
    	$str = mb_convert_encoding($str, "UCS-2","auto");
    	return $str;
    }
    Code:
    	   $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

  6. #6
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hai folks,

    This worked!

    Code:
    <?php
    $strTerm = '7302';
    echo mb_convert_encoding(bin2hex(mb_convert_encoding($strTerm, 'UCS-2', 'auto')), 'UCS-2', 'auto');
    ?>
    output : 0037003300300032

    Thank you.

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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

  8. #8
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    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/...atell_HTTP.pdf

    * load that pdf and search for the text UCS

  9. #9
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Thank you!

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

  10. #10
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Thank you!

    (after some digging around maybe its because of Javascript Encoding, maybe they use node.js?)
    hmm not sure about that


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •