Younis
Younis

Reputation: 45

api fcm push notifications using php Error : JSON_PARSING_ERROR: Unexpected token END OF FILE at position 0

Hi guys I push notifications fcm using php when i send title or body in Arabic Language The result error :

JSON_PARSING_ERROR: Unexpected token END OF FILE at position 0.

just in Arabic Language

this is my code:

<?php



define( 'API_ACCESS_KEY', 'my api server key');

$registrationIds = ('token')
$msg = array
(
        'body'  => 'هلاو', 
        'title' => 'مرحبا',
        'icon'  => 'myicon',/*Default Icon*/
        'sound' => 'mySound'/*Default sound*/
);
$fields = array
(
        'to'        => $registrationIds,
        'notification'  => $msg
);


$headers = array
(
        'Authorization: key=' . API_ACCESS_KEY,
        'Content-Type: application/json',

);
#Send Reponse To FireBase Server
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
//curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

echo $result;

I need help may be the problem in encode

Upvotes: 1

Views: 1928

Answers (1)

Anas Altair
Anas Altair

Reputation: 170

change your .php file encode to UTF-8.

from Notepad++ Encode -> Encode in UTF-8 then save file.

Upvotes: 1

Related Questions