PHP JSON特殊字符

Meh*_*zay 5 php encoding json

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

Alt nPortakal电影节soni 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);
Run Code Online (Sandbox Code Playgroud)

Phi*_*ter 12

将您的代码更改为:

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);
Run Code Online (Sandbox Code Playgroud)

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


Spo*_*oky 5

What's the output with this?

<?php
header('Content-Type: text/html');
echo(json_encode($JSON, JSON_UNESCAPED_UNICODE)); 
Run Code Online (Sandbox Code Playgroud)

JSON_UNESCAPED_UNICODE

Encodes multibyte Unicode characters literally (default is to escape as \uXXXX). Available since PHP 5.4.0.