PHP JSON特殊字符 [英] PHP JSON Special Characters

查看:214
本文介绍了PHP JSON特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该在我的手json类型中返回一些结果。但由于特殊字符,我无法输出。
内容数组中的示例数据:

There should return a number of results in my hand json type. But I can not output due to special characters. Example data in content array:


Alt nPortakal Film Festivalisonu land 。

Alt�n Portakal Film Festivali sonu�land�.

(问题:

$JSON["today"]=array();
for ($i=0; $i < count($olay_tarih); $i++) { 
    $gelen["date"] = array();
    $gelen["content"]=array();
    array_push($gelen["date"], $olay_date[$i]);
    array_push($gelen["content"], $olay_content[$i]);
    array_push($JSON["today"], $gelen);
}
echo json_encode($JSON);


推荐答案

将代码更改为:

header('Content-Type: application/json; charset=utf-8', true,200);
$JSON["today"]=array();

for ($i=0; $i < count($olay_tarih); $i++) { 
$gelen["date"]=array();
$gelen["content"]=array();
array_push($gelen["date"], $olay_date[$i]);
array_push($gelen["content"], $olay_content[$i]);
array_push($JSON["today"], $gelen);
}
$JSON = array_map('utf8_encode', $JSON);
echo json_encode($JSON);

添加UTF-8标题将使浏览器识别此设置的任何特殊字符。

Adding UTF-8 headers will make the browser recognize any special characters for this setting.

这篇关于PHP JSON特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆