【问题标题】:PHP converting PCRE unicode sequence to normal utf-8 stringPHP将PCRE unicode序列转换为普通的utf-8字符串
【发布时间】:2012-05-02 08:21:09
【问题描述】:

是否可以在 PHP 中将 unicode PCRE 序列(如 \x{2f}\x{3251})转换为字符串?

【问题讨论】:

    标签: php unicode utf-8 pcre


    【解决方案1】:

    使用html_entity_decode 是可能的

    function cb($a){
            $num = $a[1];
            $dec = hexdec($num);
            return "&#$dec;";
    }
    $ent = preg_replace_callback("/\\\\x\{([\da-z]+)\}/i", 'cb', "\x{2f}, \x{3251}");
    $ustr = html_entity_decode($ent, ENT_NOQUOTES, 'UTF-8');
    

    示例: http://ideone.com/fDNGM

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 2012-05-14
      • 1970-01-01
      • 2019-07-20
      • 2012-07-02
      • 2010-09-21
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多