How to get json_encode() to work with ISO-8859-1 (åäö)

前端 未结 8 969
礼貌的吻别
礼貌的吻别 2021-01-11 15:58

json_encode() wont work for me when I\'m using åäö. Why? And how can I get it to work?

The php:

echo json_encode($arr);
         


        
8条回答
  •  半阙折子戏
    2021-01-11 16:50

    The $data (in my case) is an array with text values as ISO-8859-1. The trick below prepares $data to be used with json_encode.

    function toUtf8(&$v, $k) {
        $v = utf8_encode($v);
    }
    array_walk_recursive($data, 'toUtf8');
    

提交回复
热议问题