该死的编码,输出怎么就不一样呢。 $str = '华南'; 改成$str = '华南';也没用。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function utf8_replaceEntity($result){ $value = (int)$result[1]; $string = ''; $len = round(pow($value,1/8)); for($i=$len;$i>0;$i--){ $part = ($value & (255>>2)) ¦ pow(2,7); if ( $i == 1 ) $part ¦= 255 <<(8-$len); $string = chr($part) . $string; $value >>= 6; } return $string; } function utf8_html_entity_decode($string){ return preg_replace_callback( '/&#([0-9]+);?/u', 'utf8_replaceEntity', $string ); } $string = '华南'; $str = '华南'; $string = utf8_html_entity_decode($string); echo iconv("UTF-8", "GB2312", $string); $str = utf8_html_entity_decode($str); echo iconv("UTF-8", "GB2312", $str); 怎么不小心点 你的编辑器里, &# 这些符号是什么编码的,我这里想保存,需要转换编码。 我读进来的文件,有5位的,也有2位的,华 | A ,2位的就要出错, Array ( [0] => 华南 [1] => SL01088 [2] => 广州世裕汽车贸易有限公司 [3] => ACTYON [4] => A200XDi[2006] [5] => 爱腾A200XDi [6] => GREY [7] => 灰色 [8] => LAK [9] => 经典黑 [10] => AH [11] => KPTC0B1K97P039397 [12] => 255000 [13] => 周婧芝 [14] => 2008-03-01 ) 终于解决了,麻烦,一个网上找的函数。function u2utf82gb($c){ $str=""; if ($c < 0x80) { $str.=chr($c); } else if ($c < 0x800) { $str.=chr(0xC0 | $c>>6); $str.=chr(0x80 | $c & 0x3F); } else if ($c < 0x10000) { $str.=chr(0xE0 | $c>>12); $str.=chr(0x80 | $c>>6 & 0x3F); $str.=chr(0x80 | $c & 0x3F); } else if ($c < 0x200000) { $str.=chr(0xF0 | $c>>18); $str.=chr(0x80 | $c>>12 & 0x3F); $str.=chr(0x80 | $c>>6 & 0x3F); $str.=chr(0x80 | $c & 0x3F); } return iconv('UTF-8', 'GB2312', $str);} php调用JS提问 请大家帮忙测试一下我的花生壳 一个简单的日期型字段的处理问题 ! 跪求,PHP发MAIL,加入背景音乐的问题。。。 紧急求助 php 中有类似asp里response.redriect功能的函数吗? window2000下的PHP+mysql+phpmyadmin. 为什么我找不到上传的文件??? 一个很普通的问题,关于参数传递的,高手求救,谢谢 php高手,来吧!交流无边界! 大家帮看看,有几个问题。 关于循环输出数据库记录的问题.急求解!!!!!!!!!!!!!
function utf8_replaceEntity($result){
$value = (int)$result[1];
$string = '';
$len = round(pow($value,1/8));
for($i=$len;$i>0;$i--){
$part = ($value & (255>>2)) ¦ pow(2,7);
if ( $i == 1 ) $part ¦= 255 <<(8-$len);
$string = chr($part) . $string;
$value >>= 6;
}
return $string;
} function utf8_html_entity_decode($string){
return preg_replace_callback(
'/&#([0-9]+);?/u',
'utf8_replaceEntity',
$string
);
}
$string = '华南';
$str = '华南';
$string = utf8_html_entity_decode($string);
echo iconv("UTF-8", "GB2312", $string);
$str = utf8_html_entity_decode($str);
echo iconv("UTF-8", "GB2312", $str); 怎么不小心点
Array
(
[0] => 华南
[1] => SL01088
[2] => 广州世裕汽车贸易有限公司
[3] => ACTYON
[4] => A200XDi[2006]
[5] => 爱腾A200XDi
[6] => GREY
[7] => 灰色
[8] => LAK
[9] => 经典黑
[10] => AH
[11] => KPTC0B1K97P039397
[12] => 255000
[13] => 周婧芝
[14] => 2008-03-01
)
$str="";
if ($c < 0x80) {
$str.=chr($c);
} else if ($c < 0x800) {
$str.=chr(0xC0 | $c>>6);
$str.=chr(0x80 | $c & 0x3F);
} else if ($c < 0x10000) {
$str.=chr(0xE0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3F);
$str.=chr(0x80 | $c & 0x3F);
} else if ($c < 0x200000) {
$str.=chr(0xF0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3F);
$str.=chr(0x80 | $c>>6 & 0x3F);
$str.=chr(0x80 | $c & 0x3F);
}
return iconv('UTF-8', 'GB2312', $str);
}