json decode 안될 때
·
Development/PHP
json decode 안될 때 확인해야할 것 1. json 양식이 맞는지 확인 텍스트 내용 및 앞 뒤로 {} 괄호가 잘 있는지 확인한다. ""(쌍따옴표)로 감싸져있는게 올바른 양식이며, '(홑따옴표)는 지원하지않는다. 홑따옴표가 있다면 쌍따옴표로 변경해준다. $strHtmlList = str_replace("'",'"',$strHtmlList); json 양식에 맞는 데이터인지 꼭 확인한다. 2. 공백이 있는 경우 올바른 json 양식은 불필요한 공백이 없다. 해당 부분을 체크하자 json decode 안될 때 사용할 함수 공백, " \ 포함되어있으면 json 변환이 안됨 null, 스페이스 포함 preg_replace 써서 정리하기 - UTF-8용 정리 $text = preg_replace('/[\x0..
유니코드 변환(decode)
·
Development/PHP
# unicode decode function utf8_urldecode($str) { $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); return html_entity_decode($str,null,'UTF-8');; } # use $str = utf8_urldecode($str); 참고 : https://www.php.net/manual/en/function.urldecode.php
[PHP] 공백이 한 칸 이상일 때 공백 제거
·
Development
$str = preg_replace("/\s{2,}/"," ",$str); // 공백이 2개이상일때 한 개로 대체