In this tutorial we going to learn how to build regional or foreign language website using PHP and MySQL. Let see.
Step 1:
Create new table in the name of article. Character 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 collationlatin1_swedish_ci to utf8_general_ci.
Step 2:
Just insert new row with regional or foreign language like below.
INSERT INTO articles(title,description) VALUES (N' درس خصوصي', N' Lernprogramm');
Step 3:
To display other languages in browser we need to include below line of code.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Step 4:
Use below code will display stored data from mysql database. Before that you have to specifymysql_query() function data character set type.
<html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <?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 } ?> </html>
Thats all! you will now get region/foreign content website.
Have a nice day!