简体   繁体   中英

how to send unicode value in url without changing?

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM