[ php ] json 한글 깨지는 현상 해결 > php

본문 바로가기
사이트 내 전체검색

php

[ php ] json 한글 깨지는 현상 해결

페이지 정보

작성자 웹지기 댓글 0건 조회 8,574회 작성일 18-08-28 14:05

본문

배열을 json_encode()해서 json으로 바꿀 때 한글 값이 유니코드로 깨져 들어가는 현상을 해결하는 방법

PHP 버젼별로 다르게 구현


PHP 5.3 이하

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');

}

$array = array("foo","bar");

$result = my_json_encode($array);


PHP 5.4 이상

$array = array("foo","bar");

$result = json_encode($array,JSON_UNESCAPED_UNICODE);

[이 게시물은 웹지기님에 의해 2018-08-28 14:20:06 그누보드5에서 이동 됨]
추천0 비추천0

댓글목록

등록된 댓글이 없습니다.

Total 82건 8 페이지
게시물이 없습니다.
게시물 검색

회원로그인

접속자집계

오늘
6,497
어제
15,358
최대
33,828
전체
8,321,277

그누보드5
Copyright © funyphp.com. All rights reserved.