PHP Convert encoding

529 Views Asked by At

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

0

There are 0 best solutions below