【问题标题】:php mysql codeigniter character encodingphp mysql codeigniter 字符编码
【发布时间】:2016-04-04 12:11:41
【问题描述】:

我正在使用 codeIgniter 并具有以下设置,但我的网页仍然显示“?”如果是特殊字符。

数据库 - UTF-8 编码 表 - UTF-8 列-UTF-8 在 html 文件中,我添加了以下行

<? header("Content-Type: text/html; charset=UTF-8"); ?>

37摄氏度显示为“保持在37摄氏度”

等特殊字符也显示错误。

【问题讨论】:

  • 这适用于我的本地 xampp 环境。仅在生产中遇到问题

标签: php codeigniter encoding utf-8


【解决方案1】:

设置这个

config.php

$config['charset'] = "UTF-8";

在数据库连接中

$db['default']['char_set'] = "utf8"; 
$db['default']['dbcollat'] = "utf8_unicode_ci";

在文件的标题中

echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
// Generates:  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

【讨论】:

  • 我有同样的设置。我页面上的 Phpinfo() 给出了 "charset-utf-8" 但仍然没有显示字符。
【解决方案2】:

添加

<?php header('Content-type: text/html; charset=iso-8859-1'); ?>

到我的 html 标头对我有用!!!!

【讨论】:

  • 这意味着你没有使用utf8!
【解决方案3】:

请尝试使用 utf8_general_ci 排序规则。

$db['default']['dbcollat'] = "utf8_general_ci";

如果您的问题仍未解决,则在您的数据库表中将列排序规则设置为 utf8_general_ci。

这会起作用。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多