We send iOS / Apple devices push notifications through PHP / Java firewalls.
The problem we are facing is that Java has different multibyte characters that PHP does.
For example, below is the Arabic text that we must send, one from the Java backend and one from the PHP backend system (PHP and the Java backend are both different, no relationship with each other):
يبدا بقرص العقيلي واللقيمات وينتهي مع خالد حرية بالامارات نكهة وبهار مع القصار-٦ مساءا على تلفزيون الكويت
Now when we check the length of the string:
Java: length 106 byte 194 PHP: length 369 byte 547
Apple now allows only 256 bytes payload to be used, so the Java backend can fully send the aforementioned Arabic text, while not allowed in PHP. We need to reduce the text for PHP.
Below is my PHP code:
// PHP Interpretation: echo $str = 'يبدا بقرص العقيلي واللقيمات وينتهي مع خالد حرية بالامارات نكهة وبهار مع القصار-٦ مساءا على تلفزيون الكويت'; echo '<br><br>'; $payload['aps'] = array('alert' => $str, 'sound' => 'default'); $payload = json_encode($payload); echo $payload; echo strlen($payload); echo '<br><br>'; echo '<br><br>'; echo utf8_encode($str); echo '<br><br>'; echo json_encode($str); echo '<br><br>'; echo strlen(json_encode($str)); echo '<br>'; echo strlen(utf8_encode($str)); echo '<br>'; echo mb_strlen(json_encode($str));
Does anyone ever face this problem? Any known solution for this?
Please inform.
source share