无法在PHP中回显印地语字符

时间:2019-01-14 10:04:51

标签: php mysql sql

我正在尝试以json格式回显sql表,该sql数据为印地语和英语。我检查了一些答案,说使用charset我尝试仍在打印。

<?php
header('Content-Type: charset=utf-8');

require "conn.php";
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, 
$db_name);
if($conn === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}


mysqli_query("SET CHARACTER SET utf8");

$sql = "SELECT * FROM hindi_question ";




 $result = mysqli_query($conn, $sql) or die("Error in Selecting " . 
 mysqli_error($conn));

//create an array
$emparray = array();
while($row =mysqli_fetch_assoc($result))
{
    $emparray[] = $row;
}
// echo json_encode($emparray);


echo json_encode(array("result"=>$emparray) , 
JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
//close the db connection
mysqli_close($conn);


?>

输出是这个

{"result":[{"sno":"1","question":"?????? ?? ???? ???\r\n?????? ????? ???????","o1":"?????? ?? ???? ???\r\n?????? ????? ???????","o2":"?????? ?? ???? ???\r\n?????? ????? ???????","o3":"?????? ?? ???? ???\r\n?????? ????? ???????","o4":"?????? ?? ???? ???\r\n?????? ????? ???????","r_o":"?????? ?? ???? ???\r\n?????? ????? ???????","tag":"?????? ?? ???? ???\r\n?????? ????? ???????","month":"?????? ?? ???? ???\r\n?????? ????? ???????","day":"11","lang":"Hindi"}]}

任何帮助或链接来解决此问题,将不胜感激。谢谢

1 个答案:

答案 0 :(得分:0)

尝试使用       mysql_query(“ SET NAMES utf8”); 代替       mysql_query(“ SET CHARACTER SET utf8”);