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

时间:2016-05-08 20:11:32

标签: php arrays json

ON senses.synsetid = synsets.synsetid
where senses.wordid = 79459

我试过CREATE TABLE `synsets` ( `synsetid` int(10) unsigned NOT NULL DEFAULT '0', `pos` enum('n','v','a','r','s') NOT NULL, `definition` mediumtext, PRIMARY KEY (`synsetid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE `words` ( `wordid` int(10) unsigned NOT NULL DEFAULT '0', `lemma` varchar(80) NOT NULL, `mantiq` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`wordid`), UNIQUE KEY `unq_words_lemma` (`lemma`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE `senses` ( `wordid` int(10) unsigned NOT NULL DEFAULT '0', `synsetid` int(10) unsigned NOT NULL DEFAULT '0', `senseid` int(10) unsigned DEFAULT NULL, `sensekey` varchar(100) DEFAULT NULL, PRIMARY KEY (`wordid`,`synsetid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE `samples` ( `synsetid` int(10) unsigned NOT NULL DEFAULT '0', `sampleid` smallint(5) unsigned NOT NULL DEFAULT '0', `sample` mediumtext NOT NULL, PRIMARY KEY (`synsetid`,`sampleid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 但是没有用; ERROR

$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/..

2 个答案:

答案 0 :(得分:0)

试试这个(PHP5.4.0 +)

json_encode($result, JSON_UNESCAPED_UNICODE);

答案 1 :(得分:0)

您需要添加以下代码

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

为我工作