如何将 中国人民 转成 汉字"中国人民"? echo utf8_decode("中国人民"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?phpecho utf8_decode("中国人民");//output :中国人民 ?>不是乱码 $str=utf8_decode(("中国人民");然后将它写入数据库没问题的或者直接写入,然后读出来的时候再转换 找到转换办法了,这是一个10进制方式显示的Unicode字符需要先下载一个Unicode的转换Classhttp://www.phpe.net/class/95.shtml然后<?php include("./encoding/encoding.inc.php"); $source = "中国人民"; // 原代码 $newstr = ""; $strEncoding=new Encoding(); $strEncoding->SetGetEncoding("UTF-16LE") || die("编码名错误"); $strEncoding->SetToEncoding("GBK")||die("编码名错误"); $chars = explode("&#",$source); // 将字code分割到Array for( $i=0; $i<sizeof($chars); $i++ ) { $newstr .= $strEncoding->EncodeString(pack("I",$chars[$i])); // Unicode到GBK转换 } echo $newstr;?> <?php/** * 转换unicode十进制内码为utf-8编码 */function u2utf8($c) { $str=""; if ($c < 0x80) { $str.=$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 $str; }$source = "中国人民";preg_match_all("/&#([0-9]+)/",$source,$regs);print_r($regs);foreach($regs[1] as $v) $source = str_replace("&#$v",iconv("UTF-8","GB2312",u2utf8($v)),$source);echo $source;?> 曾经写过一个 js 的~~~~~~~~~<script language="JavaScript">function Unicode2oStr(str){ var re=/&#[\da-fA-F]{1,5};/ig; var arr=str.match(re); if(arr==null)return(""); for(var i=0;i<arr.length;i++){ arr[i]=String.fromCharCode(arr[i].replace(/[&#;]/g,"")); } return(arr.toString().replace(/,/g,""))}alert(Unicode2oStr("中国人民"));</script> apache rewrite规则 跪求大神救命啊 国外网站信用卡支付流程? UTF8页面获取的GET和POST值中的中文都是乱码 关于字符串转化 数组循环 求助!一个关于str_replace()问题? 初来轧道,简单问题,php怎么来实现包含页面的代码, 如何做弹出页面? 急!急!急!自写com组件访问数据库问题 如题在adodb.php中有没有一个方法可以返回 update语句,影响的行数 用GD可以生成动态GIF吗? 紧急求助:SESSION失效期问题
echo utf8_decode("中国人民");//output :中国人民
?>不是乱码
然后将它写入数据库没问题的
或者直接写入,然后读出来的时候再转换
<?php
include("./encoding/encoding.inc.php"); $source = "中国人民"; // 原代码
$newstr = ""; $strEncoding=new Encoding();
$strEncoding->SetGetEncoding("UTF-16LE") || die("编码名错误");
$strEncoding->SetToEncoding("GBK")||die("编码名错误"); $chars = explode("&#",$source); // 将字code分割到Array
for( $i=0; $i<sizeof($chars); $i++ )
{
$newstr .= $strEncoding->EncodeString(pack("I",$chars[$i])); // Unicode到GBK转换
}
echo $newstr;
?>
/**
* 转换unicode十进制内码为utf-8编码
*/
function u2utf8($c) {
$str="";
if ($c < 0x80) {
$str.=$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 $str;
}$source = "中国人民";preg_match_all("/&#([0-9]+)/",$source,$regs);
print_r($regs);
foreach($regs[1] as $v)
$source = str_replace("&#$v",iconv("UTF-8","GB2312",u2utf8($v)),$source);
echo $source;
?>
function Unicode2oStr(str){
var re=/&#[\da-fA-F]{1,5};/ig;
var arr=str.match(re);
if(arr==null)return("");
for(var i=0;i<arr.length;i++){
arr[i]=String.fromCharCode(arr[i].replace(/[&#;]/g,""));
}
return(arr.toString().replace(/,/g,""))
}alert(Unicode2oStr("中国人民"));
</script>