안녕하세요.


php json_encode를 사용하면 한글은 유니코드로 보여지게 됩니다 \u....  이런식으로 말이죠.


그런데, 한글로 json을 output 내야할 때 JSON_UNESCAPED_UNICODE을 사용하면 됩니다.


사용방법은


$arr = array("안녕"=>"개발자");

json_encode($arr);     


output => 유니코드로 나오게 됩니다.


$arr = array("안녕"=>"개발자");

json_encode($arr,JSON_UNESCAPED_UNICODE );     


output => 정상적으로 한글로 나오게 됩니다.


그런데 php 버젼이 5.4 이하라면 JSON_UNESCAPED_UNICODE  옵션이 정상 작동을 안 하게 됩니다.

>>리눅스 상에서 php -version으로 확인 가능.


그렇다면 php버젼을 5.4로 업그레이드 하면 되겠죠?


업그레이드 방법입니다.


1. wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm && rpm -Uvh epel-release-latest-6.noarch.rpm

2. wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm

3. vi /etc/yum.repos.d/remi.repo

  >> [remi] 부분에 있는 enabled=0을 1로 변경 enabled=1

4. yum -y update php*

5. 업데이트 완료시 웹서버 재시작.

6. php -version 으로 5.4 확인


해당 업그레이드 방법은 CentOS release 6.5에서 진행하였습니다.


그런 다음 JSON_UNESCAPED_UNICODE  옵션을 사용하면 정상적으로 한글이 output 되는 걸 볼 수 있습니다.




+ Recent posts