0

I'm using a php SMPP class to receive SMS messages. When the data_coding value is 8, I can't read the contents that is in UCS-2 encoding.

I tried using iconv('UTF-16BE','UTF-8',$sms['short_message']) and mb_convert_encoding($sms['short_message'], 'UTF-8', 'UCS-2'), but it doesn't give me the right text.

Running a mb_detect_encoding($sms['short_message']) told me that it sees it as UTF-8, which is wrong. The original text (05d405d505d305e205d4002005d105e205d105e805d905ea) is definitely in UCS-2 encoding and I need to convert it to UTF-8.

Does any one have an idea what to do?

BTW, if anyone is familiar with the great encoding site http://rishida.net/tools/conversion/ , when I put the coded text there (I have to put spaces between each 2 bytes, though) and click on the "Convert numbers as UTF-16 units", it converts it successfully, so there has to be a way to do it...

UPDATE: I added the following function and it does the conversion, but only of the actual text:

function my_numeric2character($t)
    {
        $convmap = array(0x0, 0xffff, 0, 0xffff);
        return mb_encode_numericentity($t, $convmap, 'UCS-2');
    } 

The problem is that it doesn't convert special characters like space, dot and so on. It also doesn't work with French special characters like è é ê ...

Thanks in advance,

David

david
  • 43
  • 1
  • 7
  • Have you tried mb_convert_encoding using auto? As in this solution: http://stackoverflow.com/questions/1872773/ucs2-hexencoded-characters – arikin Mar 05 '14 at 04:28
  • possible duplicate of [PHP - UTF-16 to UTF-8(hex) conversion](http://stackoverflow.com/questions/2670039/php-utf-16-to-utf-8hex-conversion) – Paul Sweatte Oct 06 '14 at 22:35

0 Answers0