"यदि कोई कर्मचारी अपना काम अच्छी तरह से करना चाहता है, तो उसे पहले अपने औजारों को तेज करना होगा।" - कन्फ्यूशियस, "द एनालेक्ट्स ऑफ कन्फ्यूशियस। लू लिंगगोंग"
मुखपृष्ठ > प्रोग्रामिंग > How to Store and Display Unicode Strings in Hindi Using PHP and MySQL?

How to Store and Display Unicode Strings in Hindi Using PHP and MySQL?

2024-11-08 को प्रकाशित
ब्राउज़ करें:261

How to Store and Display Unicode Strings in Hindi Using PHP and MySQL?

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

  • For the MySQL database, set the database and table encoding to UTF-8 and use the utf8_bin collation to ensure proper handling of Unicode characters.
  • In the table itself, ensure that the text field accepts UTF-8 text by setting the charset property to 'utf8'.

PHP Script

  • To display the Unicode string correctly, you must set the Content-Type header as follows:
header('Content-Type: text/html; charset=utf-8');
  • Additionally, you can specify the character set for MySQL queries by setting NAMES utf8 before executing any query that retrieves data. For instance:
$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

  • Double-check that your HTML head section includes the appropriate charset:
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  • If you encounter any issues, try escaping Unicode characters before inserting them into the database. You can achieve this using functions like htmlentities() or htmlspecialchars().

By implementing these measures, you should be able to store and display Unicode strings in Hindi correctly using PHP and MySQL.

विज्ञप्ति वक्तव्य यह आलेख यहां पुनर्मुद्रित है: 1729600276 यदि कोई उल्लंघन है, तो कृपया इसे हटाने के लिए स्टडी_गोलंग@163.कॉम से संपर्क करें।
नवीनतम ट्यूटोरियल अधिक>

चीनी भाषा का अध्ययन करें

अस्वीकरण: उपलब्ध कराए गए सभी संसाधन आंशिक रूप से इंटरनेट से हैं। यदि आपके कॉपीराइट या अन्य अधिकारों और हितों का कोई उल्लंघन होता है, तो कृपया विस्तृत कारण बताएं और कॉपीराइट या अधिकारों और हितों का प्रमाण प्रदान करें और फिर इसे ईमेल पर भेजें: [email protected] हम इसे आपके लिए यथाशीघ्र संभालेंगे।

Copyright© 2022 湘ICP备2022001581号-3