CodeIgniter的配置字符集和UTF-8支持 [英] CodeIgniter config charset and UTF-8 support

查看:334
本文介绍了CodeIgniter的配置字符集和UTF-8支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用/在数据库中使用/存储重音字符的网站。我设置了页面模板,以便 config.php 字符集变量匹配设置,例如:

I'm working on a website which uses / stores accented characters in the database. I have the page template set so that the config.php charset variable matches the setting, e.g.:

<meta charset="<?php echo $this->config->item('charset');?>">

我遇到的问题是,当 $ config ['charset' ] 设置为 UTF-8 ,表单验证失败,如果包含重音字符,则没有提交字符。因此,例如,如果á包含在字符串中的任何位置,则必填字段将反弹。

The problem I'm having is, when $config['charset'] is set to UTF-8, the form validation fails and it's as if no characters were submitted if an accented character was included. So, for example, a required field will bounce back if á is included anywhere in the string. The string minus the á works fine.

我已经设法通过改变 $ config ['charset'] utf8_encode()从数据库中检索之前/之后将文本转换为 ISO-8859-1 并将文本转换为UTF-8 utf8_decode()。这是最好的方法,或者我缺少一些东西,以获得UTF-8,使用重音字符,在CodeIgniter工作。

I've managed to get this working by changing the $config['charset'] to ISO-8859-1 and converting text to UTF-8 before inserting / after retrieving from the database with php's utf8_encode() and utf8_decode(). Is this the best way or am I missing something needed in order to get UTF-8, with accented characters, working in CodeIgniter?

任何建议赞赏。

Any advice appreciated.

推荐答案

你必须确保你使用UTF-8无处不在,PHP和MySQL都配置为处理UTF-8。

You have to make sure that you use UTF-8 everywhere, and that both PHP and MySQL are configure to handle UTF-8.

在html中,添加元标记:

In the html, add the meta-tag:

<meta charset="utf-8" />

并以UTF-8格式保存。这里是如何在记事本++ 中执行此操作。

And save it in UTF-8 format. here is how to do that in notepad++.

定义MySQL表以支持UTF-8,创建表格为:

Define the MySQL tables to support UTF-8, create table with:

DEFAULT CHARSET=utf8;

并将连接设置为:

mysql_set_charset('utf8', $con);

php.ini 中启用UTF-8

Enable UTF-8 in the php.ini:

default_charset = "utf-8"

完全手动检查在Web应用程序中处理Unicode前后关系

这篇关于CodeIgniter的配置字符集和UTF-8支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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