Hindi / Marathi text not displaying in php

The simple solution to the problem of not displaying Hindi, Marathi, or any other regional language text in PHP is to use the below query immediately after the server connection statement.

Step 1:

mysqli_set_charset($conn,”utf8mb4″);

<?php
$servername = "localhost";
$username = "User_MName";
$password = "Password";
$dbname = "database_name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
mysqli_set_charset($conn,"utf8mb4");
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
?>

Step 2:

Go to the MySQL database and set the “Collation” to below utf settings.

utf8mb4_general_ci

Thats it. This will solve your problem.

The above solution works if the text is saved in the UTF-8 format in your MySQL database. Hence, login to the MySQL database and check the database entries to confirm the data is visible in the preferred language. If the data is stored as error text such as “?????????” or displayed as corrupt data, then you need to check the script that you are using to enter the data in the database.

If the issue persists after implementing the above code, let us know in the comment box.

Related Posts

Leave a Reply