相关疑难解决方法(0)

通过PHP解码数字html实体

我有这个代码将数字html实体解码为UTF8等效字符.

我正在尝试转换这个角色:

应该输出:

"

然而,它只是消失(没有输出).(我已经检查了页面的源代码,页面有正确的utf8字符集标题/元标记).

有谁知道代码有什么问题?

function entity_decode($string, $quote_style = ENT_COMPAT, $charset = "UTF-8") {    
     $string = html_entity_decode($string, $quote_style, $charset);

     $string = preg_replace_callback('~&#x([0-9a-fA-F]+);~i', "chr_utf8_callback", $string);
     $string = preg_replace('~&#([0-9]+);~e', 'chr_utf8("\\1")', $string);

    //this is another method, which also doesn't work.. 
     //$string = preg_replace_callback("/(\&#[0-9]+;)/", "entity_decode_callback", $string);

     return $string; 
}




function chr_utf8_callback($matches) { 
     return chr_utf8(hexdec($matches[1])); 
}

function chr_utf8($num) {   
     if ($num < 128) return chr($num);
     if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
     if ($num …
Run Code Online (Sandbox Code Playgroud)

html php utf-8 character-encoding

3
推荐指数
1
解决办法
4810
查看次数

标签 统计

character-encoding ×1

html ×1

php ×1

utf-8 ×1