PHP - Displaying Urdu text retrieved from MySQL DB
database, functional-programming, mysql, php
Solution
Step : 1 - Go to table structure and change collation latin1_swedish_ci to utf8_general_ci
Step : 2 - You have to include this following tag in data results pages.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Step :3 - Insert 'N' Prefix. Here the N stands for National language character set. Which means that you are passing an NCHAR, NVARCHAR or NTEXT value, more
Step :4 - 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 books") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
echo $row['id']; // Book id
echo $row['books_title']; // Book title
}
?>
Problem
There are book titles in Urdu language stored in MySQL database. I've to display on html page using PHP. Currently only questions marks(`??????`) are displayed in place of Urdu text. ``` <div class='product_title'><a href='details.php?pid=".$Row['s_id']."'>".$Row["books"]."</a></div> ``` What needs to be done to display these characters properly?