HTML文档的字符编码未声明为codeigniter

时间:2013-02-13 03:11:05

标签: php html codeigniter character-encoding

我的CodeIgniter应用程序已经开始出现怪异错误:

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

在第一次访问时,页面显示正常,只是消息" guimbu" 。如果刷新页面,则会在清除浏览器历史记录之前显示错误。 这仅在第二次页面查看后发生。看看:http://guimbu.com/soon

  • 我刚用Sublime打开所有文件并保存到UTF-8;两次。
  • 我刚试过所有charset元标记;
  • 所有页面都会发生这种情况,包括这个简单的页面;

我的autoload.php有这个:

$autoload['packages'] = array();
$autoload['libraries'] = array('session', 'database', 'firephp', 'auth');
$autoload['helper'] = array('url', 'log_helper', 'api_helper', 'string_helper');
$autoload['config'] = array('ci_opauth', 'rest', 'ci_auth');
$autoload['language'] = array();
$autoload['model'] = array();

如何调试此问题?

更新

@sudhir,谢谢你的回答,但我多次尝试过。实际上源代码只是:

<!DOCTYPE html>
<head>
    <title>guimbu</title>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
</head>
<body>
    guimbu =)
</body>
</html>

第二次页面视图后错误仍然存​​在= / 会议可能有问题吗?

更新可能性:

当我从 autoload 中删除会话身份验证库时,问题不会发生。 WTF? auth 是我为用户身份验证而创建的库。

3 个答案:

答案 0 :(得分:2)

当您刷新该页面时,您会得到一个空白页面,如果您查看源该页面,您将看到它是空白的,具有数字计数。我的猜测是,当页面刷新时会向浏览器发送一个空白区域。我只能建议不要用?>关闭你的文件,让php处理你的脚本退出/死亡的方式。你的代码中有一些空格导致了这一点。

答案 1 :(得分:1)

尝试在视图的主题部分添加这些内容:

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

答案 2 :(得分:0)

找到解决方案

在Session类构造函数的第一行中,它加载String helper。 昨天我创建了一个名为 string_helper.php 的助手,这个冲突就是崩溃的应用程序。

我重命名了我的string_helper.php文件,现在一切正常。

全部谢谢!