Home >Backend Development >PHP Tutorial >How to Store and Display Unicode (Hindi) Strings in PHP and MySQL?
Storing and Displaying Unicode String (हिन्दी) in PHP and MySQL
When attempting to store and display Hindi text in a MySQL database using PHP, you may encounter encoding issues. To resolve these issues, ensure the following steps are taken:
<code class="sql">SET NAMES utf8; ALTER DATABASE YOUR_DATABASE_NAME CHARACTER SET = utf8 COLLATE = utf8_bin;</code>
<code class="php">$result = mysql_query("SELECT * FROM your_table"); while ($row = mysql_fetch_assoc($result)) { echo utf8_encode($row['hindi_column']); }</code>
<code class="html"><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></code>
Additionally, you can set the content type in your PHP script using:
<code class="php">header('Content-Type: text/html; charset=utf-8');</code>
Understanding the Solution Script:
The provided script works without specifying a meta tag or header info because it explicitly sets the NAMES to utf8 using the mysql_query() function. This ensures that the connection and queries use the UTF-8 character set, enabling proper display of Hindi text.
Tips:
The above is the detailed content of How to Store and Display Unicode (Hindi) Strings in PHP and MySQL?. For more information, please follow other related articles on the PHP Chinese website!