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

본문 바로가기

사이트 내 전체검색

php

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

작성일 18-08-28 14:05

페이지 정보

작성자 웹지기 조회 8,687회 댓글 0건

본문

배열을 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

댓글목록

등록된 댓글이 없습니다.

전체 82건 6 페이지

이미지 목록

게시물 검색
Copyright © 즐거운 코딩 생활 ( funyphp ). All rights reserved.
PC 버전으로 보기