Thursday, November 20, 2014

Get Support with Regional and Foreign Language in PHP

AS we know that default setting of PhpMyadmin does not support the foreign and regional language. It support the English language by default. So, Here I am going to show you that how to insert the regional as well as foreign language in a mysql database with using php.

 Regional and Foreign Language in PHP

Click Here to See Live Demo

In the above image, you can see the current situation of database. You need to insert the foreign language in the ????????????????? Form or in another form which is not readable. So, let's check, how to solve this query.

HTML META TAG

Html meta tag must in the character set of UTF-8.

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

SAMPLE DATABASE STRUCTURE

Database name --> 2my4edge
Table name -->comment
Column names --> id, msg, ip_add

and the character set should be UTF-8 format.

While building database table, You should follow the below steps.


In a collation the value taken as latin1_swedish-ci, we have to change that in the format of utf8_general_ci.


INSERT CODE 

You need to add prefix as N while inserting code. N is set for national regional language character set. 

mysql_query("INSERT INTO `comment`(msg,ip_add) values (N'$content',N'$ip')");

FETCH CODE

Now, need to add the character set type in php while fetching from the database. 

<?php 
include('db.php'); 
mysql_query ("set character_set_results='utf8'"); 
---- fetching code --- 
?>

0 comments:

Post a Comment