PHP - JSON编码土耳其语字符随着奇怪的字符而变化

时间:2017-06-07 15:15:38

标签: php json utf-8

我正在研究json数组,但土耳其字符随着奇怪的字符而变化。例如:

  • ı - > ı,有时候it(太奇怪了)
  • ü - > ö,
  • İ - > ý

...

我尝试了什么?

 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 != "&nbsp;"){
        $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);

1 个答案:

答案 0 :(得分:-2)

您必须使用字符集utf8

PDO JSON代码示例

view details

<?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);