您可能已经来混合编码类型了。例如。以iso-8859-1发送但从MySQL或XML获取UTF-8文本编码的页面通常会失败。
要解决此问题,您必须相对于您选择使用内部编码的类型来保持对输入编码类型的控制。
如果将其作为iso-8859-1发送,则来自用户的输入也是iso-8859-1。
header("Content-type:text/html; charset: iso-8859-1");如果mysql发送latin1,则您无需执行任何操作。
但是,如果您输入的不是iso-8859-1,则必须在将其发送给用户之前对其进行转换,或者在存储之前使其适应Mysql。
mb_convert_encoding($text, mb_internal_encoding(), 'UTF-8'); // If it's UTF-8 to internal encoding
简短地说,这意味着您必须始终将输入转换为适合内部编码,并转换输出以匹配外部编码。
这是我选择使用的内部编码。
mb_internal_encoding('iso-8859-1'); // Internal encoding这是我使用的代码。
mb_language('uni'); // Mail encodingmb_internal_encoding('iso-8859-1'); // Internal encodingmb_http_output('pass'); // Skipfunction convert_encoding($text, $from_pre='', $to_pre=''){ if (empty($from_pre)) { $from_pre = mb_detect_encoding($text, 'auto'); if ($from_pre == 'ASCII') { $from_pre = 'iso-8859-1'; } } if (empty($to_pre)) { return mb_convert_encoding($text, mb_internal_encoding(), $from_pre); } return mb_convert_encoding($text, $to_pre, $from_pre);}function encoding_html($text, $pre=''){ if (empty($pre)) { return htmlentities($text, ENT_NOQUOTES, mb_internal_encoding()); } return mb_convert_encoding(htmlentities($text, ENT_NOQUOTES, $pre), mb_internal_encoding(), $pre);}function decoding_html($text, $pre=''){ if (empty($pre)) { return html_entity_depre($text, ENT_NOQUOTES, mb_internal_encoding()); } return mb_convert_encoding(html_entity_depre($text, ENT_NOQUOTES, $pre), mb_internal_encoding(), $pre);}


