json_encode 시 한글 깨짐 현상

json_encode 시 한글 깨짐 현상이 있다.

정확히 말하면 깨진 것이 아니고 unicode 로 변환 된 것인데

php 5.4 버전에서는 json_array($array,JSON_UNESCAPED_UNICODE) 로 해결 할 수 있다고 하는데

안될 경우 아래의 함수를 이용하면 된다.


function my_json_encode($arr)
{
        //convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters are being "hidden" from normal json_encoding
        array_walk_recursive($arr, function (&$item, $key) { if (is_string($item)) $item = mb_encode_numericentity($item, array (0x80, 0xffff, 0, 0xffff), 'UTF-8'); });
        return mb_decode_numericentity(json_encode($arr), array (0x80, 0xffff, 0, 0xffff), 'UTF-8');

}
@http://php.net/manual/kr/function.json-encode.php#105789