0

One of my PHP sms application I am trying to send unicode character but it will gives some unwanted character in my sms. But when I am trying send through direct url it will gives me perfect result. I am totally confused how I will implement in my application.

my application code generate below url


function sendMsg($message,$contactNo) 
    { 

            $ch = curl_init();
        $rno = urlencode(utf8_encode($contactNo));
        $txt = urlencode(utf8_encode($message));
        $txt=preg_replace('/%0A/',"", $txt);

                curl_setopt($ch,CURLOPT_URL,"http://sms.*****.com/reseller/sendsms.jsp?user=****&password=****&mobiles=******&sms=$txt&senderid=******&unicode=1"); 


        $buffer = curl_exec($ch);
        curl_close($ch);
                if($buffer==FALSE){
                    return FALSE;
                }else{
                    return TRUE;

                }
    }

I am getting value of txt = %E5%BC%95%E3%81%8D%E5%89%B2%E3%82%8A

Direct URL

http://sms.*****.com/reseller/sendsms.jsp?user=****&password=****&mobiles=******&sms=ಯುನಿಕೋಡ್&senderid=******&unicode=1
  • 2
    I certainly hope that you are not sending a username and password via a http request. – AgeDeO Dec 30 '15 at 14:10
  • if you want to send _utf-8_ chars, then urlencoded `ಯುನಿಕೋಡ್` is `%E0%B2%AF%E0%B3%81%E0%B2%A8%E0%B2%BF%E0%B2%95%E0%B3%86%E0%B3%82%E0%B3%95%E0%B2%A1%E0%B3%8D`. See [this answer](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Federkun Dec 30 '15 at 14:10
  • You should worry more about the visibility of the password than your unicode problem. – trincot Dec 30 '15 at 14:34

1 Answers1

0

PHP strings are bytes. So $message contains your text encoded in some encoding.

Look carefully at the documentation of utf8_encode, it only works if the input string is encoded as ISO-8859-1. That character set cannot encode text in scripts other than Latin, like “ಯುನಿಕೋಡ್”.

So you have to know what encoding was used to encode the bytes in $message. We cannot tell that from your example code. If it already is UTF-8, then remove the call to utf8_encode. Otherwise you need a conversion function where you also specify the encoding of the input string, like iconv.

roeland
  • 5,349
  • 2
  • 14
  • 28