我在网上看到一行中文转成了  宝腿弯   这样格式的,请问是用哪个函数转的,如何还原?

解决方案 »

  1.   

    html_entity_decode 转的中文,只能用眼睛看到,网页底层还是那个码。。
      

  2.   

    $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
      

  3.   

    兄弟,你将 宝腿弯  这三个,转成三个中文字看看,我用你的都不对。
    运行后查看源文件也要是中文。
    html_entity_decode 运行后查看还是没转之前的状态
      

  4.   

    <?phpfunction html_entity_decode_utf8($string)
    {
        static $trans_tbl;
        
        // replace numeric entities
        $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\1"))', $string);
        $string = preg_replace('~&#([0-9]+);~e', 'code2utf(\1)', $string);    // replace literal entities
        if (!isset($trans_tbl))
        {
            $trans_tbl = array();
            
            foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
                $trans_tbl[$key] = utf8_encode($val);
        }
        
        return strtr($string, $trans_tbl);
    }
    function code2utf($num)
    {
        if ($num < 128) return chr($num);
        if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
        if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
        if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
        return '';
    }echo html_entity_decode_utf8("&#x5B9D;&#x817F;&#x5F2F;");