0

I am using SMPP Receiver API to get the messages from specific MSISDN. I am getting the English text correctly. But the Dari and Pashto text is not in same format. It shows output like below :
/
'2(�
/'HFD/1

My Code is :

ob_start();
require_once "smpp.php";//SMPP protocol
//connect to the smpp server
$tx=new SMPP('IP',PORT);
//bind the receiver
$tx->system_type="NUll";
$tx->addr_npi=0;
$tx->bindReceiver("username","password");
do
{
//read incoming sms
  if($sms=$tx->readSMS())
  {
    print_r($sms);
  }
}while($sms);

And smpp.php is at :

http://121.100.50.58/apps/smpp/

How I can get the correct Dari and Pashto Language Message text?

Sushil Kandola
  • 870
  • 2
  • 9
  • 22

3 Answers3

2

Try this

$utf8 = $body;

$encodedMessage = mb_convert_encoding($utf8, "UCS-2", "utf8");
$from = new SmppAddress($sender, SMPP::TON_ALPHANUMERIC);
$to = new SmppAddress($number, SMPP::TON_INTERNATIONAL, SMPP::NPI_E164);

$smppClient->sendSMS($from, $to, $encodedMessage, [], SMPP::DATA_CODING_UCS2);

It works completly for polish characters and I'm pretty sure it works with all unicode.

Danon
  • 2,771
  • 27
  • 37
0

Save the .php script itself in utf-8. This also has to line up with the charset in your browser.

If that still doesnt work, check out mb_convert_encoding http://de2.php.net/manual/en/function.mb-convert-encoding.php.

biplav
  • 781
  • 6
  • 13
  • hey @biplav, still it has same problem. – Sushil Kandola Jun 18 '14 at 11:17
  • @SushilKandola: Where are you seeing the output? Is it on telnet or something, it might not be utf8 compliant. Can you write it to a file and open with a editor which support Utf8. – biplav Jun 18 '14 at 11:21
  • Yeah, I have written the file too, but same format. Even I inserting the data to sql database, it supports UTF-8. – Sushil Kandola Jun 18 '14 at 11:55
  • Which editor did you use to view your file. Please go through this http://www.joelonsoftware.com/articles/Unicode.html to understand how unicode works. Whatever junk you are getting means that the content is there but you are not able to view it correctly. – biplav Jun 18 '14 at 13:08
  • Biplav, If I print some static values of Dari and Pashto Lang, then browser shows the exact same output. As I think, SMPP is returning some garbage values which browser don't understand. – Sushil Kandola Jun 19 '14 at 05:15
  • Check dataCoding on your SMPP. Read this link, it might help: http://stackoverflow.com/questions/11985088/meaning-of-data-coding – biplav Jun 19 '14 at 06:00
  • It also not helpful @biplav. If I use mb_detect_encoding, it shows UTF-8. String : (~0�1/ Encoding : UTF-8 – Sushil Kandola Jun 19 '14 at 08:48
  • @SushilKandola And what your encoding on the message received. You need to check based on above link. – biplav Jun 19 '14 at 09:04
  • I am getting the same format(UTF-8) on received messages :( – Sushil Kandola Jun 19 '14 at 09:16
-1

The text seems to be sent from the SMSC in UNICODE. It should be just a matter of using the correct encoding and charset ... try using charset UTF16-BE and encoding UCS2

  • SMPP response is not in Unicode, Its different for different languages. As browser supports Unicode and UTF-8, so it should return all output in same format. Even If I am using UTF-16-BE decoding, it returns garbage value for English text. – Sushil Kandola Jun 24 '14 at 05:41