我遇到了关于$ _POST字符集的问题。当我提交表单时,在InputText上插入的字符串有一个特殊字符或重音,$ _POST数组上此输入的值被无效字符损坏。
例: 我插入输入:“pão” $ _POST告诉我:数组([输入] =>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">
答案 0 :(得分:2)
尝试此解决方案,在脚本中插入此jquery函数:
现金: Javier Poo,WeLinux S.A. Oficina:02-372.97.70,Celular:84039925 Bombero 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());
}
});
答案 1 :(得分:0)
你能改变一切到utf8吗?包括数据库?
如果是,请更改所有文件,并将MySQL数据库(和表)设置为utf8_general_ci
。如果您使用notepad ++进行开发,请转到Encoding > Encode in UTF-8
(emportuguêsFormatar > Codificação em UTF-8
)。
尽量不要将ISO-8859-1用作字符编码。
答案 2 :(得分:0)
然后你需要“转换”所有文件和数据库做ISO-8859-1。不要忘记在PHP / HTML文件中添加编码。
例如,在HTML4中:<meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1">
和HTML5:<meta charset="ISO-8859-1">
另外,请尝试将<form>
代码中的teh enctype更改为application/x-www-form-urlencoded
并查看其是否有效。