dsigg21445 2016-09-03 15:20
浏览 57
已采纳

PHP UTF-8编码回应问号

I'm trying to echo a json_response with unicode characters using the following code:

function utf8ize($d) {
if (is_array($d)) {
    foreach ($d as $k => $v) {
        $d[$k] = utf8ize($v);
    }
} else if (is_string ($d)) {
    return utf8_encode($d);
}
return $d;
}

used like this:

echo json_encode(utf8ize($response));

The problem with this is that some characters are encoded properly and other characters like ć and ś are sent as question marks as seen in the below image:

enter image description here

I'm not sure how to fix this.

  • 写回答

2条回答 默认 最新

  • dragoninasia2014 2016-09-03 15:27
    关注

    You could try to execute

    SET NAMES utf8
    

    As a query. After you've made the connection.

    Then just in case set this header

    header('Content-type: text/plain; charset=utf-8');
    

    Then try again

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部