mysql没有阅读特殊的utf8(øœå)字符

时间:2022-05-09 01:06:48

After reading from my database, special characters are not displayed correctly.

从我的数据库中读取后,特殊字符无法正确显示。

I am connecting to my database in this fashion:

我以这种方式连接到我的数据库:

$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB     connection');

mysql_select_db($db_database,$link);
mysql_query("SET names UTF8");

?>

I am reading the database in this fashion:

我正在以这种方式阅读数据库:

$rs = mysql_query("SELECT id, name FROM tags ");
while($row = mysql_fetch_array($rs))
{
    //Read each tag into a span-menu
    echo "<div class=\"span-3\"id=\"".$row['id']."\">"."<a href=\"activities.php?tag_id=".$row['id']."&tag=".$row['name']."\"><h5>".$row['name']."</h5></a></div>\n ";

}

The table contains correct characters, so the problem is when they are read....

该表包含正确的字符,因此问题在于它们被读取....

Any ideas?

Thx

1 个解决方案

#1


0  

It's likely to be your HTML page which is showing the wrong encoding, rather than mysql (or your query).

它可能是您的HTML页面显示错误的编码,而不是mysql(或您的查询)。

If you are using HTML5, add the following to the <head> of your html:

如果您使用的是HTML5,请将以下内容添加到html的中:

<meta charset="utf-8">

If you are using HTML4/XHTML, it's:

如果您使用的是HTML4 / XHTML,那就是:

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

You can see which encoding your page is returning and test different encodings using your browser. In Chrome, click View > Encoding.

您可以查看页面返回的编码,并使用浏览器测试不同的编码。在Chrome中,单击“查看”>“编码”。

#1


0  

It's likely to be your HTML page which is showing the wrong encoding, rather than mysql (or your query).

它可能是您的HTML页面显示错误的编码,而不是mysql(或您的查询)。

If you are using HTML5, add the following to the <head> of your html:

如果您使用的是HTML5,请将以下内容添加到html的中:

<meta charset="utf-8">

If you are using HTML4/XHTML, it's:

如果您使用的是HTML4 / XHTML,那就是:

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

You can see which encoding your page is returning and test different encodings using your browser. In Chrome, click View > Encoding.

您可以查看页面返回的编码,并使用浏览器测试不同的编码。在Chrome中,单击“查看”>“编码”。