PHP编码不正确? [英] Incorrect encoding from PHP?

查看:152
本文介绍了PHP编码不正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我在数据库中有一个表 tbl_Data ,它具有文本比较方法(?)属性的名称列设置为 utf8_polish_ci 。作为一个魅力,当我通过phpMyAdmin浏览 tbl_Data

1) I have a table tbl_Data in database which has name column with text comparision method (?) property set toutf8_polish_ci. Works as a charm, when I'm browsing tbl_Data through phpMyAdmin.

2)在我的html代码中,得到:

2) In my html code I've got:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">

所以好像我正在为浏览器发送正确的编码标头...

so seems like I'm sending proper encoding headers for browser...

3)我的PDO dsn包含; charset = UTF-8 ,其后从php手册。

3) My PDO dsn contains ;charset=UTF-8, followed from php manual.

4)在我的php代码中,我使用:

4) In my php code I use:

foreach(parent::query('SELECT ID,PLName,LatinName from tbl_Data') as $row) {
    $result = $result."
        <tr>
            <td>".utf8_encode($row['PLName'])."</td>
        </tr>
    ";
}

有了所有这一切,我仍然得到垃圾(= )字符,而不是正确的抛光字母,虽然其中一些显示很好(phpMyAdmin显示所有正确)。我在这里失踪了请求建议,伙计!

Having all of this I'm still getting 'garbage' (=?) chars instead of proper polish letters, though some of them are displaying well (phpMyAdmin shows all properly). What I am missing here? Please advice, fellows!

我的MySQL引擎是 InnoDB ,webserver: nginx fpm如果它是可怕的...

My MySQL Engine is InnoDB, webserver: nginx with fpm if it is revelant...

推荐答案


所以好像我为浏览器发送正确的编码标头。

so seems like I'm sending proper encoding headers for browser.

错误。 < meta> 不是HTTP标头,而是HTML标签,非标准标签。所以,你的代码仍然缺少适当的标题。

Wrong. <meta> is not an HTTP header but HTML tag, a non-standard one. So, your code still lacks proper header.

header('Content-Type: text/html; charset=utf-8');




我的PDO dsn包含; charset = UTF-8,其后从php手册。

My PDO dsn contains ;charset=UTF-8, followed from php manual.

如果您的PHP版本小于5.3.6,它也不会工作。使用 SET NAMES utf8 定期查询

if your PHP version is less than 5.3.6 it won't work either. use SET NAMES utf8 regular query instead

这篇关于PHP编码不正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆