\u7684\u9996\u9009\u3002<br><br>---\u66F4\u591A如何将上面的字符串中的\u后面的十六进制转换成十进制数字?

解决方案 »

  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);
    }
      

  2.   


    //本人测试通过。
    $str='\u7684\u9996\u9009\u3002<br><br>---\u66F4\u591A';
    preg_match_all('/(\\\u.{4})/i',$str,$matches);
    foreach($matches[0] as $value)
        echo hexdec($value).'<br/>';/*
    30340
    39318
    36873
    12290
    26356
    22810
    */
      

  3.   

    动用这个utf8_html_entity_decode函数
      

  4.   

    $data           = "\u7684\u9996\u9009\u300F<br><br>---\u66F4\u591A";
    $returnvalue    = '';
    function test3($matches) {
        global $returnvalue;
        $returnvalue .= $matches[1].hexdec($matches[2]).$matches[3];
    }preg_replace_callback("|(\\\u)(.*)(\\\u)|U", "test3", $data);
    print_R($returnvalue);