Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cyrillic characters in PHP's json_encode

Tags:

json

php

utf-8

I'm trying to encode Cyrillic UTF-8 array to JSON string using php's function json_encode. The sample code looks like this:

<?php
  $arr = array(
     'едно' => 'първи',
     'две' => 'втори'
  );
  $str = json_encode($arr);
  echo $str;
?>

It works fine but the result of the script is represented as:

{"\u0435\u0434\u043d\u043e":"\u043f\u044a\u0440\u0432\u0438","\u0434\u0432\u0435":"\u0432\u0442\u043e\u0440\u0438"}

which makes 6 characters for each Cyrillic character. Is there a way to get the original characters for key/value pairs instead of encoded ones?

like image 350
AquilaX Avatar asked Jan 04 '09 09:01

AquilaX


1 Answers

Can't you use JSON_UNESCAPED_UNICODE constant here?

like image 161
Alexander Farber Avatar answered Sep 19 '22 13:09

Alexander Farber