Home > Database > Mysql Tutorial > How to Store and Retrieve Unicode Data for Hindi Language in MySQL and PHP?

How to Store and Retrieve Unicode Data for Hindi Language in MySQL and PHP?

Linda Hamilton
Release: 2024-11-16 01:43:03
Original
1011 people have browsed it

How to Store and Retrieve Unicode Data for Hindi Language in MySQL and PHP?

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:

  • Choose the utf8 character set and utf8_general_ci collation for the MySQL database and table fields.
  • Use the mysql_set_charset('utf8') function in PHP to set the character set before interacting with the database.

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
Copy after login

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" />
Copy after login

Example:



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template