PHPʵÏÖgb2312¡¢UTF-8µÈ×Ö·ûºÍunicode¼äµÄ±àÂëת»»¼°PHP°æunescape
PHPʵÏÖgb2312¡¢UTF-8µÈ×Ö·ûºÍunicode¼äµÄ±àÂëת»»¼°PHP°æunescape
<? /** * ½«×Ö·û´®×ª»»³Éunicode±àÂë * * @param string $input * @param string $input_charset * @return string */ function str_to_unicode($input, $input_charset = 'gbk'){ $input = iconv($input_charset, "gbk", $input); preg_match_all("/[\x80-\xff]?./", $input, $ar); $b = array_map('utf8_unicode_', $ar[0]); $outstr = join("", $b); return $outstr; } function utf8_unicode_($c, $input_charset = 'gbk'){ $c = iconv($input_charset, 'utf-8', $c); return utf8_unicode($c); } // utf8 -> unicode function utf8_unicode($c) { switch(strlen($c)) { case 1: return $c; case 2: $n = (ord($c[0]) & 0x3f) << 6; $n += ord($c[1]) & 0x3f; break; case 3: $n = (ord($c[0]) & 0x1f) << 12; $n += (ord($c[1]) & 0x3f) << 6; $n += ord($c[2]) & 0x3f; break; case 4: $n = (ord($c[0]) & 0x0f) << 18; $n += (ord($c[1]) & 0x3f) << 12; $n += (ord($c[2]) & 0x3f) << 6; $n += ord($c[3]) & 0x3f; break; } return "&#$n;"; } /** * ½«unicode×Ö·ûת»»³ÉÆÕͨ±àÂë×Ö·û * * @param string $str * @param string $out_charset * @return string */ function str_from_unicode($str, $out_charset = 'gbk'){ $str = preg_replace_callback("|&#([0-9]{1,5});|", 'unicode2utf8_', $str); $str = iconv("UTF-8", $out_charset, $str); return $str; } function unicode2utf8_($c){ return unicode2utf8($c[1]); } function unicode2utf8($c){ $str=""; if ($c < 0x80) { $str.=$c; } else if ($c < 0x800) { $str.=chr(0xC0 | $c>>6); $str.=chr(0x80 | $c & 0x3F); } else if ($c < 0x10000) { $str.=chr(0xE0 | $c>>12); $str.=chr(0x80 | $c>>6 & 0x3F); $str.=chr(0x80 | $c & 0x3F); } else if ($c < 0x200000) { $str.=chr(0xF0 | $c>>18); $str.=chr(0x80 | $c>>12 & 0x3F); $str.=chr(0x80 | $c>>6 & 0x3F); $str.=chr(0x80 | $c & 0x3F); } return $str; } /** * Ä£ÄâJSÀïµÄunescape * * @param unknown_type $str * @return unknown */ 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-2","GB2312",pack("H4",substr($v,-4))); elseif(substr($v,0,3) == "") $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,3,-1))); elseif(substr($v,0,2) == "&#") { echo substr($v,2,-1)." "; $ar[$k] = iconv("UCS-2","GB2312",pack("n",substr($v,2,-1))); } } return join("",$ar); } ?>
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ