A
A
apacho2282021-08-31 23:52:09
PHP
apacho228, 2021-08-31 23:52:09

How to decode the letter "yo"?

There is a json file with text where there is a letter "ё" :
[{
"id": 25,
"pid": "0CjqYfx3NU1AghsPVoGFullXwl4umV",
"message": "Just yo is crazy!"
}]


Function to decode json to utf-8 :

function normJsonStr($str) {
    $pattern = "/\\\\u([a-f0-9]{4})/i";
    $callback = function ($m) {
          return chr(hexdec($m[1])-1072+224);
      };
      $str = preg_replace_callback($pattern, $callback, $str);
      return iconv('CP1251', 'UTF-8', $str);
  }


As a result, I get this:
[{
"id": 25,
"pid": "0CjqYfx3NU1AghsPVoGFullXwl4umV",
"message": "That's crazy!"
}]


I output everything in this way: It is
echo normJsonStr(json_encode($json));

necessary that e be like e :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-08-31
@apacho228

Why do we need all this perversion?

$data = ;
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
/*
[
    {
        "id": 25,
        "pid": "0CjqYfx3NU1AghsPVoGFullXwl4umV",
        "message": "Одно лишь ё - это безумие!"
    }
]
*/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question