PHP - Displaying Urdu text retrieved from MySQL DB

那年仲夏 提交于 2019-12-21 04:09:23

问题


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?


回答1:


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
}
?>



回答2:


Also your files encoding mustbe utf-8 without BOM




回答3:


I had faced this problem and i have solved this error by convert them to UTF-8.

ALTER TABLE test_Table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

ALTER TABLE test_Table_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

ALTER TABLE test_Table_name CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci;


来源:https://stackoverflow.com/questions/11280421/php-displaying-urdu-text-retrieved-from-mysql-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!