Storing and Displaying Unicode String (हिन्दी) Using PHP and MySQL
You may encounter challenges when attempting to store and display Unicode strings, particularly in languages like Hindi, due to encoding issues. To address these concerns, it's essential to set the appropriate character encoding and collation in both your database and the PHP script.
Database Configuration
PHP Script
header('Content-Type: text/html; charset=utf-8');
$result = mysql_query("SET NAMES utf8");
Sample Script
The following PHP script demonstrates how to store and retrieve Unicode text in a MySQL database and display it on a web page:
<?php
include("connection.php"); // Database connection settings
// Set charset for MySQL queries
$result = mysql_query("SET NAMES utf8");
// Query to retrieve data from the database
$cmd = "SELECT * FROM hindi";
$result = mysql_query($cmd);
while ($myrow = mysql_fetch_row($result)) {
echo ($myrow[0]);
}
?>
In the script, ensure you have included a database connection file named "connection.php" with the necessary settings to connect to your MySQL database.
Additional Considerations
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
By implementing these measures, you should be able to store and display Unicode strings in Hindi correctly using PHP and MySQL.
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3