L
L
Leonid2011-03-23 15:11:57
PHP
Leonid, 2011-03-23 15:11:57

json_encode and cyrillic

Dear colleagues, please tell me how you deal with this: I read about json_safe_encode - but the reverse (decode) does not work (does not show the “value”). In general, how do you take it off?
$foo = array("key"=>"значение");
$json = json_encode($foo);
var_dump($json);
/*Результат: string(13) "{"name":null}" */

Answer the question

In order to leave comments, you need to log in

6 answer(s)
M
MaZaAa, 2014-08-03
@MaZaAa

Much easier...
json_encode($res, JSON_UNESCAPED_UNICODE);

H
Hint, 2011-03-23
@Hint

Use utf-8.

R
RomAndry, 2011-03-23
@RomAndry

Use UTF-8

A
Anton Korzunov, 2011-03-23
@kashey

1. the Internet is full of classes for working with json in any locale, but they are 1000 times slower than the built-in function
2. no one bothers to go through the input, find all the lines (or all the lines you need) and pass them through iconv
3. yes, the only super stable option is utf-8 everywhere

D
Dmitry Tallmange, 2011-03-23
@p00h

www.php.net/manual/en/function.json-encode.php#102178

J
Jazzist, 2011-03-23
@Jazzist

json_encode($foo); - what's in the server locale?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question