如何使用PHP显示Unicode数据

时间:2021-09-08 08:34:07
table 'abc' data :

tid    title

  1      வெள்ளிக்கிழமை ஐ.

  2      கோலாகல தொடக்க 


$sql=mysql_query("select title from abd where tid='1'");

$row=mysql_fetch_array($sql);

$title = $row['title'];

echo $title;

OutPut displaying like this:

????????????????

But I want to display

வெள்ளிக்கிழமை ஐ.

Solution

<?php
    mysql_query ("set character_set_results='utf8'");   

    $sql=mysql_query("select title from abd where tid='1'");

    $row=mysql_fetch_array($sql);

    $title = $row['title'];

    echo $title;

?>

6 个解决方案

#1


35  

Try to set charachter encoding after mysql_connect function like this:

尝试在mysql_connect函数之后设置charachter编码,如下所示:

 mysql_query ("set character_set_client='utf8'"); 
 mysql_query ("set character_set_results='utf8'"); 

 mysql_query ("set collation_connection='utf8_general_ci'"); 

#2


6  

Try to make sure the browser recognizes the page as Unicode.

尝试确保浏览器将页面识别为Unicode。

Generally, this can be done by having your server send the right Content-type HTTP header, that includes the charset you're using.

通常,这可以通过让您的服务器发送正确的Content-type HTTP标头来完成,其中包括您正在使用的字符集。


For instance, something like this should work :

例如,像这样的东西应该工作:

header('Content-type: text/html; charset=UTF-8');
echo "வெள்ளிக்கிழமை ஐ";


If this works, and your dynamically generated page still doesn't :

如果这样做,并且您的动态生成的页面仍然没有:

  • make sure your data in your MySQL database is in UTF-8 too
    • this can be set for each table, or even columns, in MySQL
    • 这可以在MySQL中为每个表甚至列设置
  • 确保MySQL数据库中的数据也是UTF-8,这可以在MySQL中为每个表甚至列设置
  • and make sure you are connecting to it using UTF-8.
  • 并确保使用UTF-8连接到它。

Basically, all your application should use the same encoding :

基本上,您的所有应用程序都应使用相同的编码:

  • PHP files,
  • PHP文件,
  • Database
  • 数据库
  • HTTP server
  • HTTP服务器

#3


5  

For new version of PHP which used mysqli, use this code after connect to mysql:

对于使用mysqli的PHP新版本,在连接到mysql后使用此代码:

mysqli_set_charset($link, 'utf8');

#4


3  

execute query

执行查询

SET NAMES 'utf8'

right after connecting to database

在连接到数据库之后

#5


1  

First you need to convert your mysql data format to utf-8, see this great article by oreilly:

首先,您需要将您的mysql数据格式转换为utf-8,请参阅oreilly的这篇精彩文章:

.

Turning MySQL data to UTF-8

将MySQL数据转换为UTF-8

.

After that make sure that your page's encoding type is utf-8:

之后,请确保您的页面的编码类型为utf-8:

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

#6


0  

<?php header('Content-type: text/html; charset=UTF-8');echo "<font face='Bamini' size='5'>" . "m.Nkhfd; Fkhh;" ."<br />";
echo "<font face='Bamini' size='10'>" . "m.Nkhfd; Fkhh;" ."<br />";
?>

or

<?php
header('Content-type: text/html; charset=UTF-8');
echo "வெளà¯à®³à®¿à®•à¯à®•à®¿à®´à®®à¯ˆ à®";
?>

#1


35  

Try to set charachter encoding after mysql_connect function like this:

尝试在mysql_connect函数之后设置charachter编码,如下所示:

 mysql_query ("set character_set_client='utf8'"); 
 mysql_query ("set character_set_results='utf8'"); 

 mysql_query ("set collation_connection='utf8_general_ci'"); 

#2


6  

Try to make sure the browser recognizes the page as Unicode.

尝试确保浏览器将页面识别为Unicode。

Generally, this can be done by having your server send the right Content-type HTTP header, that includes the charset you're using.

通常,这可以通过让您的服务器发送正确的Content-type HTTP标头来完成,其中包括您正在使用的字符集。


For instance, something like this should work :

例如,像这样的东西应该工作:

header('Content-type: text/html; charset=UTF-8');
echo "வெள்ளிக்கிழமை ஐ";


If this works, and your dynamically generated page still doesn't :

如果这样做,并且您的动态生成的页面仍然没有:

  • make sure your data in your MySQL database is in UTF-8 too
    • this can be set for each table, or even columns, in MySQL
    • 这可以在MySQL中为每个表甚至列设置
  • 确保MySQL数据库中的数据也是UTF-8,这可以在MySQL中为每个表甚至列设置
  • and make sure you are connecting to it using UTF-8.
  • 并确保使用UTF-8连接到它。

Basically, all your application should use the same encoding :

基本上,您的所有应用程序都应使用相同的编码:

  • PHP files,
  • PHP文件,
  • Database
  • 数据库
  • HTTP server
  • HTTP服务器

#3


5  

For new version of PHP which used mysqli, use this code after connect to mysql:

对于使用mysqli的PHP新版本,在连接到mysql后使用此代码:

mysqli_set_charset($link, 'utf8');

#4


3  

execute query

执行查询

SET NAMES 'utf8'

right after connecting to database

在连接到数据库之后

#5


1  

First you need to convert your mysql data format to utf-8, see this great article by oreilly:

首先,您需要将您的mysql数据格式转换为utf-8,请参阅oreilly的这篇精彩文章:

.

Turning MySQL data to UTF-8

将MySQL数据转换为UTF-8

.

After that make sure that your page's encoding type is utf-8:

之后,请确保您的页面的编码类型为utf-8:

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

#6


0  

<?php header('Content-type: text/html; charset=UTF-8');echo "<font face='Bamini' size='5'>" . "m.Nkhfd; Fkhh;" ."<br />";
echo "<font face='Bamini' size='10'>" . "m.Nkhfd; Fkhh;" ."<br />";
?>

or

<?php
header('Content-type: text/html; charset=UTF-8');
echo "வெளà¯à®³à®¿à®•à¯à®•à®¿à®´à®®à¯ˆ à®";
?>