Chris
Chris

Reputation: 35

How to view hindi font on Browser in json format

I want to display text in Hindi for that I change Collation to utf8_general_ci in MySQL but when I try to view data in JSON format using PHP it's showing ??? instead of नकद. Here is my web service:

    <?php
        require_once 'include/DB_Config.php';

// Create connection
$conn =new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);    

if ($conn->connect_error) {
 die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM receipt";
$result = $conn->query($sql);

if ($result->num_rows >0) {
 // output data of each row
 while($row[] = $result->fetch_assoc()) {

 $tem = $row;

 $json = json_encode($tem);


 }

} else {
 echo "0 results";
}
 echo $json;
$conn->close();
?>

Try to use echo json_encode($tem, JSON_UNESCAPED_UNICODE); what can I do to display hindi font in Browser from php.

Upvotes: 1

Views: 813

Answers (1)

Nicolae Natea
Nicolae Natea

Reputation: 1194

set the charset after creating the connection

$conn =new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
$conn->set_charset("utf8");

more details on http://php.net/manual/ro/mysqli.set-charset.php

otherwise it's likely still latin depending on your php instalation

Upvotes: 1

Related Questions