Character encoding $\u POST上的字符集无效
我对$u POST的字符集有一个问题。当我提交表单时,如果InputText上插入的字符串具有特殊字符或重音,则$\u POST数组上此输入的值已被无效字符损坏 例如: 我在输入中插入:“pão” $u POST show me:Array([input]=>pÃo) 我正在使用带有ISO-8859-1字符集的CodeIgniter框架。为了改进我的测试,我使用了mb_detect_encoding(),该函数返回utf-8:\ 以下是重要部件的代码:Character encoding $\u POST上的字符集无效,character-encoding,Character Encoding,我对$u POST的字符集有一个问题。当我提交表单时,如果InputText上插入的字符串具有特殊字符或重音,则$\u POST数组上此输入的值已被无效字符损坏 例如: 我在输入中插入:“pão” $u POST show me:Array([input]=>pÃo) 我正在使用带有ISO-8859-1字符集的CodeIgniter框架。为了改进我的测试,我使用了mb_detect_encoding(),该函数返回utf-8:\ 以下是重要部件的代码: /* |-----------------
/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
*/
$config['charset'] = "iso-8859-1";
/*
|--------------------------------------------------------------------------
| Default Language
|--------------------------------------------------------------------------
|
| This determines which set of language files should be used. Make sure
| there is an available translation if you intend to use something other
| than english.
|
*/
$config['language'] = "portugues";
$db['default']['char_set'] = "latin1";
$db['default']['dbcollat'] = "latin1_swedish_ci";
Form that was submited:
<form action="HTTP://localhost/portalsibe/index.php/grupos/cadastro" id="form" accept-charset="utf8" method="POST" name="frmPadrao" target="" enctype="multipart/form-data">
/*
|--------------------------------------------------------------------------
|默认字符集
|--------------------------------------------------------------------------
|
|这将确定默认情况下在各种方法中使用的字符集
|需要提供字符集的。
|
*/
$config['charset']=“iso-8859-1”;
/*
|--------------------------------------------------------------------------
|默认语言
|--------------------------------------------------------------------------
|
|这决定了应该使用哪一组语言文件。确保
|如果您打算使用其他语言,则有可用的翻译
|比英语好。
|
*/
$config['language']=“葡萄牙语”;
$db['default']['char\u set']=“拉丁1”;
$db['default']['dbcollat']=“拉丁语和瑞典语”;
提交的表格:
您能将所有内容更改为utf8吗?包括数据库
如果是,请更改所有文件,并将MySQL数据库(和表)设置为utf8\u general\u ci
。如果您正在使用记事本++进行开发,请转到编码>UTF-8编码
(em português格式>codecocaèo em UTF-8
)
尽量不要使用ISO-8859-1作为字符编码。然后您需要“转换”所有文件和数据库,并执行ISO-8859-1。别忘了在PHP/HTML文件中添加编码
例如,在HTML4:
和HTML5:
另外,尝试将
标记中的enctype更改为应用程序/x-www-form-urlencoded
,看看它是否有效。尝试此解决方案,在脚本中插入此jquery函数:
学分:
韦利努克斯有限公司。
奥菲西纳:02-372.97.70,塞勒尔:84039925
Bomberro Ossa#1010,圣地亚哥
www.welinux.cl
jQuery.fn.extend({
param: function( a ) {
var s = [];
// If an array was passed in, assume that it is an array
// of form elements
if ( a.constructor == Array || a.jquery ){
// Serialize the form elements
jQuery.each( a, function(){
s.push(unescape(encodeURIComponent(escape(this.name))) + "=" + unescape(encodeURIComponent(escape(this.value))));
});
}
// Otherwise, assume that it's an object of key/value pairs
else{
// Serialize the key/values
for ( var j in a )
// If the value is an array then the key names need to be repeated
if ( a[j] && a[j].constructor == Array )
jQuery.each( a[j], function(){
s.push(unescape(encodeURIComponent(escape(j)) + "=" + encodeURIComponent(escape(this))));
});
else
s.push(unescape(encodeURIComponent(escape(j)) + "=" + encodeURIComponent(escape(a[j]))));
}
// Return the resulting serialization
return s.join("&").replace(/ /g, "+");
},
serialize: function() {
return this.param(this.serializeArray());
}
});
谢谢你,罗德里戈。。。不幸的是,我的所有项目(文件和数据库)都是ISO-8859-1/latin1(以前是正常的……例如:如果我正常使用uft-8_解码($\u POST)函数,你知道吗?