json_encode() 不显示阿拉伯字符 (opendir)


json_encode() doesn't display arabic characters (opendir)

$files = array();
$dir = opendir(dirname(realpath(__FILE__)).'/files/'.$fil_fi_row['file_name'].'/');
while ($file = readdir($dir)) {
    if ($file == '.' || $file == '..') {
        continue;
    }
    $allfiles[] = $file;
}
$total_arr=array_merge((array)$id,(array)$files);
sort($total_arr);
foreach($total_arr as $key=>$file){
    if($key != count($total_arr)-1)
        $array[‘Files’][] = array(                                         
            ‘files’ => $file,
            ‘id’ => $id,
        );
    }
}   
echo  json_encode($array, JSON_UNESCAPED_UNICODE);

我尝试了JSON_UNESCAPED_UNICODE但没有工作;错误

Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /home/...
Warning: json_encode() expects parameter 2 to be long, string given in /home/..

当我使用

echo  json_encode($array);

阿拉伯语文件名显示为:

8508_'u0645'u0635'u0631 'u0627'u0643'u0631'u0645 20150908 

您需要添加以下代码

header('Content-Type: applcation/json; charset = utf-8');
mysqli_set_charset($conn,"utf8");

为我工作

试试这个(PHP5.4.0+(

json_encode($result, JSON_UNESCAPED_UNICODE);