phpcharacter-encodingclickatell

Clickatell arabic text getting garbled


I ma trying to send arabic text from the clickatell sms provider using php, but all i have been able to send yet is garbled text. The text I am using for testing is "غثس هفس ".

I have tried encoding the message text to Windows-1256,1250 and ISO-8859-6 formats using iconv but everytimeit just sends garbled texts.

Can anyone please give me some pointers to what I am missing?

Thanks in advance


Solution

  • Ok, this is for whoever comes on this path later. Found the solution here Retaining code from Esailija's answer

    <?php
    $text = "غثس هفس خن";
    $arr = unpack('H*hex', iconv('UTF-8', 'UCS-2BE', $text));
    $message = strtoupper($arr['hex']);
    
    $username = '';
    $password = '';
    $API_ID = '';
    $to = '';
    
    $url = "http://api.clickatell.com/http/auth?user=$username&password=$password&api_id=$API_ID";
    $ret = file($url);
    $sess = explode(":",$ret[0]);
    if ($sess[0] == "OK") {
        $sess_id = trim($sess[1]);
        $url = "http://api.clickatell.com/http/sendmsg?session_id=$sess_id&to=$to&text=$message&unicode=1";
        $ret = file($url);
        $send = explode(":",$ret[0]);
    
        if ($send[0] == "ID") {
            echo "success - message ID: ". $send[1];
        } else {
            echo "send message failed";
        }
    } else {
        echo "Authentication failure: ". $ret[0];
    }