$str = '&#21326&#21335'; 改成$str = '华南';也没用。

解决方案 »

  1.   


    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 = '&#21326;&#21335;'; 
    $str = '&#21326&#21335'; 
    $string = utf8_html_entity_decode($string); 
    echo iconv("UTF-8", "GB2312", $string); 
    $str = utf8_html_entity_decode($str); 
    echo iconv("UTF-8", "GB2312", $str); 怎么不小心点
      

  2.   

    你的编辑器里, &#  这些符号是什么编码的,我这里想保存,需要转换编码。
      

  3.   

    我读进来的文件,有5位的,也有2位的,&#21326 | &#65 ,2位的就要出错,
     Array
            (
                [0] => &#21326&#21335
                [1] => &#83&#76&#48&#49&#48&#56&#56
                [2] => &#24191&#24030&#19990&#35029&#27773&#36710&#36152&#26131&#26377&#38480&#20844&#21496
                [3] => &#65&#67&#84&#89&#79&#78
                [4] => &#65&#50&#48&#48&#88&#68&#105&#91&#50&#48&#48&#54&#93
                [5] => &#29233&#33150&#65&#50&#48&#48&#88&#68&#105
                [6] => &#71&#82&#69&#89
                [7] => &#28784&#33394
                [8] => &#76&#65&#75
                [9] => &#32463&#20856&#40657
                [10] => &#65&#72
                [11] => &#75&#80&#84&#67&#48&#66&#49&#75&#57&#55&#80&#48&#51&#57&#51&#57&#55
                [12] => &#50&#53&#53&#48&#48&#48
                [13] => &#21608&#23143&#33437
                [14] => &#50&#48&#48&#56&#45&#48&#51&#45&#48&#49
            )
      

  4.   

    终于解决了,麻烦,一个网上找的函数。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);
    }