我正在研究json数组,但土耳其字符随着奇怪的字符而变化。例如:
...
我尝试了什么?
header('content-type: application/json; charset=utf-8');
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
iconv("ISO-8859-1", "UTF-8",$str)
我单独尝试了所有这些,但没有解决问题。我怎样才能解决这个问题? 这是我的代码:
foreach($html->find('table//tbody//tr//td') as $element) {
$elm = strip_tags($element->innertext);
//echo $str."<br>";
if($str != " "){
$tmp[] = iconv("ISO-8859-1", "UTF-8",$str);
} else {
$lessons["lesson"][] = $tmp;
unset($tmp);
$temp = array();
}
}
$json = json_encode($lessons,JSON_UNESCAPED_UNICODE);
print_r($json);
答案 0 :(得分:-2)
您必须使用字符集utf8
PDO JSON代码示例
<?php
header('Content-Type: application/json');
try{
$db = new PDO("mysql: host=localhost; dbname=veritabani; charset=utf8","root","mysql");
}catch(PDOException $message){
echo $message->getMessage();
}
$query = $db->prepare("SELECT id,product_name,product_price,delivery_date FROM teklif ORDER BY id");
$query->execute();
$data = $query->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($data,JSON_UNESCAPED_UNICODE);