how to display and store foreign/regional language UTF-8 data into
MySQL database using PHP code.
This post explains you to solve Unicode
data problems, just there steps you should follow take a quick look at
this post.
Database
Sample database articles table columns id, title and description. Character set should be UTF-8 format.CREATE TABLE `articles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(300) CHARACTER SET utf8 collate utf8_general_ci , `description` text CHARACTER SET utf8 collate utf8_general_ci, PRIMARY KEY (`id`) )
You can set this using PHPMyAdmin. Go to table structure and change collation latin1_swedish_ci to utf8_general_ci
Insert - Why prefix 'N'?
SQL insert statement. Here the N stands for National language character
set. Which means that you are passing an NCHAR, NVARCHAR or NTEXT value.INSERT INTO articles(title,description) VALUES (N'శ్రీనివాస్ తామాడా', N'新概念英语第');
HTML META TAG
You have to include this following tag in data results pages.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Displaying Records
Contains PHP code displaying records form database. Before that you have to specify mysql_query() function data character set type.<?php
include('db.php');
mysql_query ("set character_set_results='utf8'");
$query = mysql_query("SELECT * FROM articles") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
echo $row['title']; // Article
echo $row['description']; // Description
}
?>




0 comments:
Post a Comment
Notice : Spam Comments Will Be Deleted