How to decode Unicode escape sequences like “\u00ed” to proper UTF-8 encoded characters?

后端 未结 7 945
傲寒
傲寒 2020-11-22 01:01

Is there a function in PHP that can decode Unicode escape sequences like \"\\u00ed\" to \"í\" and all other similar occurrences?

I found si

7条回答
  •  执笔经年
    2020-11-22 01:30

    fix json values, it's add \ before u{xxx} to all +" "

      $item = preg_replace_callback('/"(.+?)":"(u.+?)",/', function ($matches) {
            $matches[2] = preg_replace('/(u)/', '\u', $matches[2]);
                $matches[2] = preg_replace('/(")/', '"', $matches[2]); 
                $matches[2] = json_decode('"' . $matches[2] . '"'); 
                return '"' . $matches[1] . '":"' . $matches[2] . '",';
            }, $item);
    

提交回复
热议问题