PHP5.3 htmlentities与json_encode的坑
今天在线上使用了
json_encode(htmlentities($value))
发现出现了!
[03-Jul-201502:52:44UTC]PHPWarning:json_encode_plus()[<ahref='function.json-encode-plus'>function.json-encode-plus</a>]:InvalidUTF-8sequenceinargumentin/home/users/ouerqiang/fbiz/framework/BizBootstrap.phponline106
乍一看,不知道出现了什么问题,经过看来资料发现PHP 5.4之前的
htmlentities(string,quotestyle,character-set)
其中character-set=SO-8859-1。
如果里面有中文的话就就乱码了不能转义了,json_encode只认UTF-8.导致出现报错。
改为
htmlentities($instance,ENT_QUOTES,'UTF-8')
解决
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。