function uc2html($str) {
$ret = '';
for( $i=0; $i<strlen($str)/2; $i++ ) {
$charcode = ord($str[$i*2])+256*ord($str[$i*2+1]);
$ret .= iconv("utf-8","gb2312",u2utf8($charcode));
}
return $ret;
}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; 
}

解决方案 »

  1.   

    function uc2html($str) {
    $ret = '';
    for( $i=0; $i<strlen($str); $i++ ) {
    if(ord($str[$i]) > 0x80) {
    $charcode = ord($str[$i])+256*ord($str[$i+1]);
    $ret .= iconv("utf-8","gb2312",u2utf8($charcode));
    }else
    $ret .= $str[$i];
    }
    return $ret;
    }
      

  2.   

    传入uc2html的参数必须是一个unicode编码的串,我不知道这个串你是从哪里来的
    所以也无法测试
      

  3.   

    to: 唠叼大哥
    是从EXCEL文档中取出的