2016-04-11 1 views
1

すべて正常です。しかし、ベンガル語のフォントをMySQLデータベースからエンコードしようとすると、その時に問題が発生しました。ベンガル語のフォントは "????????????"と表示されます。ベンガル語フォントのJSONエンコードエラー

** PHPファイル**

<?php 
define('HOST','localhost'); 
define('USER','xxxxxxx'); 
define('PASS','xxxxxxxx'); 
define('DB','xxxxxxxxx'); 

$con = mysqli_connect(HOST,USER,PASS,DB); 

$sql = "select * from bookinfo ORDER BY ID DESC"; 

$res = mysqli_query($con,$sql); 

$result = array(); 

while($row = mysqli_fetch_array($res)){ 
array_push($result, 
array('id'=>$row[0], 
    'name'=>$row[1], 
    'writter'=>$row[2], 
    'url'=>$row[3] 
    )); 
} 

echo json_encode(array("result"=>$result), JSON_UNESCAPED_UNICODE); 

mysqli_close($con); 

?> 

click here to see output result

+0

http://stackoverflow.com/questions/4076988/php-json-encode-json-decode-utf-8 –

答えて

5

最初のセットのコンテンツタイプなど。ヘッダ( 'Content-Typeの:アプリケーション/ JSON;のcharset = UTF-8')

そして、このようなあなたのクエリ

を実行する前に、UTF-8コードを設定します。

<?php 
header('Content-Type: application/json; charset=utf-8');  
define('HOST','localhost'); 
define('USER','xxxxxxx'); 
define('PASS','xxxxxxxx'); 
define('DB','xxxxxxxxx');  
$con = mysqli_connect(HOST,USER,PASS,DB);  
mysqli_query($con,"SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); 

$sql = "select * from bookinfo ORDER BY ID DESC"; 

$res = mysqli_query($con,$sql); 

$result = array(); 

while($row = mysqli_fetch_row($res)){ 
array_push($result, 
array('id'=>$row[0], 
'name'=>$row[1], 
'writter'=>$row[2], 
'url'=>$row[3] 
)); 
} 
echo json_encode(array("result"=>$result), JSON_UNESCAPED_UNICODE);  
mysqli_close($con);  
?> 

それはあなたを与えるだろう正しいフォントを期待どおりに使用してください。

+0

ありがとうございました。今働いている。ありがとう兄貴。 –

+0

よかったです。 – Khushboo

2
header('Content-Type: application/json; charset=utf-8'); 
+0

で変更を加えることはできません。同じprob。 –

+0

$ resultの出力は何ですか?それはベンゴリで表示されていますか? –

+0

あなたのテーブルフィールドはエンコードとしてUTF-8を持つ必要があります –

関連する問題