gpt4 book ai didi

php - 字符在 UTF-8 网站上显示不正确

转载 作者:太空狗 更新时间:2023-10-29 16:01:45 25 4
gpt4 key购买 nike

我已尽我所能,但此网页上的特殊字符显示不正确。

例如,在数据库中它是:

enter image description here

但在网站上是:

Nouveaux R�alistes

这是我检查过的所有内容...

数据库设置为UTF-8:

enter image description here

该页面是用 NetBeans 编写的,文档编码设置为 UTF-8:

enter image description here

页眉声明 UTF-8:

enter image description here

元字符集设置为 UTF-8:

enter image description here

我什至在我的 .htacess 中添加了以下行:

enter image description here

但还是有字符显示不正确,我从 W3C Validator 得到以下错误:

enter image description here

我觉得我已经尝试了所有方法,但还是行不通。 (我什至在 PHP 中尝试过 htmlspecialcharshtmlentities,但页面甚至没有呈现!)


更新
根据要求,这是我正在使用的代码:

class Exhibition {
public $exhibitionDetails;

public function __construct(Database $db, $exhibitionID){
$this->_db = $db;

$params['ExhibitionID'] = $exhibitionID;

$STH = $this->_db->prepare("SELECT *
FROM Exhibition
INNER JOIN Schedule
ON Exhibition.ExhibitionID = Schedule.ExhibitionID
WHERE Schedule.Visible = 1
AND Exhibition.ExhibitionID = :ExhibitionID;");

$STH->execute($params);

$this->exhibitionDetails = $STH->fetchAll(PDO::FETCH_ASSOC);

}
}

还有……

try {
$db = new Database(SITE_ROOT."/../");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$exhibition = new Exhibition($db,$_GET['id']);
} catch (PDOException $e) {
echo "<p class='error'>ERROR: ".$e->getMessage()."</p>";
}

最后……

<p><?php echo $exhibition->exhibitionDetails[0]["Desc"]; ?></p>

最佳答案

如果您正在使用 mysql_* 函数:

mysql_query("SET NAMES 'utf8'");

如果您正在使用 PDO

$dsn = 'mysql:host=localhost;dbname=testdb';
$username = 'username';
$password = 'password';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);

$dbh = new PDO($dsn, $username, $password, $options);

它设置连接编码。

关于php - 字符在 UTF-8 网站上显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16092448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com