How to send non english character in json from php? -


i have non-english word e.g 'परीक्षण' in database.i fetch data slim framework (php) , code :

        while($row=$result->fetch_assoc()){          $data[]=$row;         }          return $response->withstatus(200)         ->withheader('content-type', 'application/json')         ->write(json_encode($data)); 

the response e.g;

          [{"s.n":"1","english_word":"test","nepali_word":"???????"}] 

could please tell me how can send non-english word in json php?

you may want use json_unescaped_unicode constant

$arr = ['s.n' => 1, 'english_word' => 'test', 'nepali_word' => 'परीक्षण'];  echo json_encode($arr, json_unescaped_unicode);  // output : {"s.n":1,"english_word":"test","nepali_word":"परीक्षण"} 

live demo : https://3v4l.org/dvejs


in issue context , when using headers content-type: application/json need set charset follows:

->withheader('content-type', 'application/json;charset=utf-8;') 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -