WAP开发,NOKIA N73中文乱码,只在NOKIA N73上出现此问题
现象描述:
首先,NOKIA N73显示WAP页面中的中文没有问题,即NOKIA N73直接显示1.php和2.php;
问题是,在1.php中的输入框中输入中文,<go>到2.php,然后在2.php中显示1.php中刚刚输入的中文,显示的是乱码,而2.php中的原有的、静态的中文没问题;
附代码如下:
//------gbk2utf.php---------
<?php
//自定义的一个GBK转UTF-8的函数
function gbk2utf($gb)
{
if(!trim($gb)) return $gb;
$filename = './gb2312.php';//字符集文件
$tmp = file($filename);
$codetable = array();
while(list($key, $value) = each($tmp))
$codetable[hexdec(substr($value, 0, 6))] = substr($value, 9, 4);
$utf = '';
$str = $gb;
$zero = substr($str, -1, 1);
if($zero != '0') $zero = '';
while($str) {
if(ord(substr($str, 0, 1)) > 127) {
$temp = substr($str, 0, 2);
$str = substr($str, 2, strlen($str));
$utf .= "&#x".$codetable[hexdec(bin2hex($temp))-0x8080].';';
}
else {
$utf .= substr($str, 0, 1);
$str = substr($str, 1, strlen($str));
}
}
$utf = str_replace("&#x;", '', $utf);
return $utf.$zero;
}
?>
//--------1.php----------
<?php
//error_reporting(E_ALL);
error_reporting(0);
header('Content-Type: text/vnd.wap.wml; charset=utf-8');
require './gbk2utf.php';
$text = <<<WMLTEXT
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
<meta http-equiv="Content-Type" content="text/vnd.wap.wml; charset=utf-8"/>
</head>
<card title="">
<p>
请输入:<br/><!--Chinese, meaning "please input"-->
<input name="something"/>
<anchor>提交<!--Chinese, meaning "submit"-->
<go href="2.php" method="post">
<postfield name="something" value="$(something)"/>
</go>
</anchor>
</p>
</card>
</wml>
WMLTEXT;
echo gbk2utf($text);
?>
//----2.php---------
<?php
//error_reporting(E_ALL);
error_reporting(0);
require './gbk2utf.php';
header('Content-Type: text/vnd.wap.wml; charset=utf-8');
$text = urldecode($_POST['something']);
$c = mb_detect_encoding($text);
$text = iconv($c, 'gb2312', $text);
//$text = mb_convert_encoding($text, 'gb2312', $c);
$c1 = mb_detect_encoding($text);
$text = gbk2utf($text);
echo '<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"><wml><head><meta http-equiv="Content-Type" content="text/vnd.wap.wml; charset=utf-8"/></head><card title=""><p>', $c, $c1, $text, '</p></card></wml>';
?>
[解决办法]
對PHP不熟,也許手機送出的不是UTF-8的編碼。
建議不防做簡單的頁面,在winwap中調試好。
[解决办法]
以后需再关注,现在先帮你顶一下
[解决办法]
没遇到过这种情况.