phpÖÐmb_convert_encoding ºÍ iconv µÄÇø±ð
mb_convert_encodingÕâ¸öº¯ÊýÊÇÓÃÀ´×ª»»±àÂëµÄ¡£ÔÀ´Ò»Ö±¶Ô³ÌÐò±àÂëÕâÒ»¸ÅÄî²»Àí½â£¬²»¹ýÏÖÔÚºÃÏñÓе㿪ÇÏÁË¡£
²»¹ýÓ¢ÎÄÒ»°ã²»»á´æÔÚ±àÂëÎÊÌ⣬ֻÓÐÖÐÎÄÊý¾Ý²Å»áÓÐÕâ¸öÎÊÌâ¡£±ÈÈçÄãÓÃZend Studio»òEditplusд³ÌÐòʱ£¬ÓõÄÊÇgbk±àÂ룬Èç¹ûÊý¾ÝÐèÒªÈëÊý¾Ý¿â£¬¶øÊý¾Ý¿âµÄ±àÂëΪutf8ʱ£¬Õâʱ¾ÍÒª°ÑÊý¾Ý½øÐбàÂëת»»£¬²»È»½øµ½Êý¾Ý¿â¾Í»á±ä³ÉÂÒÂë¡£
mb_convert_encodingµÄÓ÷¨¼û¹Ù·½£º
http://cn.php.net/manual/zh/function.mb-convert-encoding.php
×öÒ»¸öGBK To UTF-8
< ?php header("content-Type: text/html; charset=Utf-8"); echo mb_convert_encoding("Š…‚SÎÒµÄÓÑ×Ð", "UTF-8", "GBK"); ?>ÔÙÀ´¸öGB2312 To Big5
< ?php header("content-Type: text/html; charset=big5"); echo mb_convert_encoding("ÄãÊÇÎÒµÄÅóÓÑ", "big5", "GB2312"); ?>²»¹ýҪʹÓÃÉÏÃæµÄº¯ÊýÐèÒª°²×°µ«ÊÇÐèÒªÏÈenable mbstring À©Õ¹¿â¡£
PHPÖеÄÁíÍâÒ»¸öº¯ÊýiconvÒ²ÊÇÓÃÀ´×ª»»×Ö·û´®±àÂëµÄ£¬ÓëÉϺ¯Êý¹¦ÄÜÏàËÆ¡£
ÏÂÃ滹ÓÐһЩÏêϸµÄÀý×Ó£º
iconv ¡ª Convert string to requested character encoding
(PHP 4 >= 4.0.5, PHP 5)
mb_convert_encoding ¡ª Convert character encoding
(PHP 4 >= 4.0.6, PHP 5)
Ó÷¨£º
string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )
ÐèÒªÏÈenable mbstring À©Õ¹¿â£¬ÔÚ php.iniÀォ; extension=php_mbstring.dll Ç°ÃæµÄ ; È¥µô
mb_convert_encoding ¿ÉÒÔÖ¸¶¨¶àÖÖÊäÈë±àÂ룬Ëü»á¸ù¾ÝÄÚÈÝ×Ô¶¯Ê¶±ð,µ«ÊÇÖ´ÐÐЧÂʱÈiconv²îÌ«¶à£»
string iconv ( string in_charset, string out_charset, string str )
×¢
Ò⣺µÚ¶þ¸ö²ÎÊý£¬³ýÁË¿ÉÒÔÖ¸¶¨Òª×ª»¯µ½µÄ±àÂëÒÔÍ⣬»¹¿ÉÒÔÔö¼ÓÁ½¸öºó׺£º//TRANSLIT ºÍ //IGNORE£¬ÆäÖÐ //TRANSLIT
»á×Ô¶¯½«²»ÄÜÖ±½Óת»¯µÄ×Ö·û±ä³ÉÒ»¸ö»ò¶à¸ö½üËƵÄ×Ö·û£¬//IGNORE »áºöÂÔµô²»ÄÜת»¯µÄ×Ö·û£¬¶øĬÈÏЧ¹ûÊÇ´ÓµÚÒ»¸ö·Ç·¨×Ö·û½Ø¶Ï¡£
Returns the converted string or FALSE on failure.
ʹÓãº
·¢ÏÖiconvÔÚת»»×Ö·û¡±¡ª¡±µ½gb2312ʱ»á³ö´í£¬Èç¹ûûÓÐignore²ÎÊý£¬ËùÓиÃ×Ö·ûºóÃæµÄ×Ö·û´®¶¼ÎÞ·¨±»±£´æ¡£²»¹ÜÔõôÑù£¬Õâ¸ö¡±¡ª¡±¶¼ÎÞ·¨×ª»»³É¹¦£¬ÎÞ·¨Êä³ö¡£ ÁíÍâmb_convert_encodingûÓÐÕâ¸öbug.
Ò»°ãÇé¿öÏÂÓà iconv£¬Ö»Óе±Óöµ½ÎÞ·¨È·¶¨Ô±àÂëÊǺÎÖÖ±àÂ룬»òÕßiconvת»¯ºóÎÞ·¨Õý³£ÏÔʾʱ²ÅÓÃmb_convert_encoding º¯Êý.
from_encoding is specified by character code name before conversion.
it can be array or string - comma separated enumerated list. If it is
not specified, the internal encoding will be used.
/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
$str = mb_convert_encoding($str, ¡°UCS-2LE¡±, ¡°JIS, eucjp-win, sjis-win¡±);
/* ¡°auto¡± is expanded to ¡°ASCII,JIS,UTF-8,EUC-JP,SJIS¡± */
$str = mb_convert_encoding($str, ¡°EUC-JP¡±, ¡°auto¡±);
Àý×Ó£º
$content = iconv(¡±GBK¡±, ¡°UTF-8//IGNORE¡å, $content);
$content = mb_convert_encoding($content, ¡°UTF-8¡å, ¡°GBK¡±);
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ