Storing Unicode Data in Hindi Language in MySQL and PHP
When working with multilingual data, it's crucial to store and retrieve it correctly. This article addresses the challenges of storing Unicode data in the Hindi language using PHP and MySQL.
How to Store Unicode Data
To store Hindi characters in a readable format, ensure the following:
Conversion on Submission
When users input Hindi data into a form, it may be in a different format. To store it accurately, use PHP to convert the data into Unicode before inserting it into MySQL.
Example:
$hindiText = $_POST['hindi_text']; // Get Hindi text from form $hindiText = iconv('UTF-8', 'UTF-8//IGNORE', $hindiText); // Convert to Unicode
Setting Content Type
To display Unicode characters correctly in a web browser, add a meta tag to the page's head section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Example:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Additional Note:
The mysql_set_charset() function has replaced mysql_query("SET CHARACTER SET utf8"). It's the recommended method for setting the character set in PHP.
The above is the detailed content of How to Store and Retrieve Unicode Data for Hindi Language in MySQL and PHP?. For more information, please follow other related articles on the PHP Chinese website!