相关关键词
关于我们
最新文章
用PHP将Unicode 转化为UTF-8的实现方法(推荐)
发布日期:2017-02-08 00:00:00
81
实例如下:
function unescape($str) { $str = rawurldecode($str); preg_match_all("/(?:%u.{4})|.{4};|\d+;|.+/U",$str,$r); $ar = $r[0]; //print_r($ar); foreach($ar as $k=>$v) { if(substr($v,0,2) == "%u"){ $ar[$k] = iconv("UCS-2BE","UTF-8",pack("H4",substr($v,-4))); } elseif(substr($v,0,3) == ""){ $ar[$k] = iconv("UCS-2BE","UTF-8",pack("H4",substr($v,3,-1))); } elseif(substr($v,0,2) == "") { $ar[$k] = iconv("UCS-2BE","UTF-8",pack("n",substr($v,2,-1))); } } return join("",$ar); } echo unescape("紫星蓝");