码迷,mamicode.com
首页 > 其他好文 > 详细

转换编码,将Unicode编码转换成可以浏览的utf-8编码

时间:2016-06-17 14:22:18      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

//转换编码,将Unicode编码转换成可以浏览的utf-8编码
public function unicodeDecode($name)
{
    $pattern = ‘/([\w]+)|(\\\u([\w]{4}))/i‘;
    preg_match_all($pattern, $name, $matches);
    if (!empty($matches))
    {
        $name = ‘‘;
        for ($j = 0; $j < count($matches[0]); $j++)
        {
            $str = $matches[0][$j];
            if (strpos($str, ‘\\u‘) === 0)
            {
                $code = base_convert(substr($str, 2, 2), 16, 10);
                $code2 = base_convert(substr($str, 4), 16, 10);
                $c = chr($code).chr($code2);
                $c = iconv(‘UCS-2‘, ‘UTF-8‘, $c);
                $name .= $c;
            }
            else
            {
                $name .= $str;
            }
        }
    }
    return $name;
}

 

转换编码,将Unicode编码转换成可以浏览的utf-8编码

标签:

原文地址:http://www.cnblogs.com/719907411hl/p/5593776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!