1

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.

Bachcha Singh
  • 3,850
  • 3
  • 24
  • 38
Chris
  • 35
  • 6
  • possible answer http://stackoverflow.com/questions/1198701/storing-and-displaying-unicode-string-%E0%A4%B9%E0%A4%BF%E0%A4%A8%E0%A5%8D%E0%A4%A6%E0%A5%80-using-php-and-mysql – Ahmed Ginani Apr 26 '17 at 11:52
  • 3
    Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Qirel Apr 26 '17 at 11:59
  • Possible duplicate of [Storing and displaying unicode string (हिन्दी) using PHP and MySQL](http://stackoverflow.com/questions/1198701/storing-and-displaying-unicode-string-%e0%a4%b9%e0%a4%bf%e0%a4%a8%e0%a5%8d%e0%a4%a6%e0%a5%80-using-php-and-mysql) – Nielsvh Apr 26 '17 at 18:13

1 Answers1

1

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

Nicolae Natea
  • 1,185
  • 9
  • 14