亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php 轉(zhuǎn)換字符串編碼 iconv與mb_convert_encoding的區(qū)別說明

 更新時間:2011年11月10日 14:25:56   作者:  
php 轉(zhuǎn)換字符串編碼 iconv與mb_convert_encoding的區(qū)別說明,需要的朋友可以參考下。
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] )
需要先啟用 mbstring 擴展庫,在 php.ini里將; extension=php_mbstring.dll 前面的 ; 去掉


string iconv ( string in_charset, string out_charset, string str )
注意:
第二個參數(shù),除了可以指定要轉(zhuǎn)化到的編碼以外,還可以增加兩個后綴://TRANSLIT 和 //IGNORE,
其中:
//TRANSLIT 會自動將不能直接轉(zhuǎn)化的字符變成一個或多個近似的字符,
//IGNORE 會忽略掉不能轉(zhuǎn)化的字符,而默認效果是從第一個非法字符截斷。
Returns the converted string or FALSE on failure.

使用:
1. 發(fā)現(xiàn)iconv在轉(zhuǎn)換字符"-"到gb2312時會出錯,如果沒有ignore參數(shù),所有該字符后面的字符串都無法被保存。不管怎么樣,這

個"-"都無法轉(zhuǎn)換成功,無法輸出。另外mb_convert_encoding沒有這個bug.
2. mb_convert_encoding 可以指定多種輸入編碼,它會根據(jù)內(nèi)容自動識別,但是執(zhí)行效率比iconv差太多;如:$str =

mb_convert_encoding($str,"euc-jp","ASCII,JIS,EUC-JP,SJIS,UTF- 8");“ASCII,JIS,EUC-JP,SJIS,UTF-8”的順序不同效果也有

差異
3. 一般情況下用 iconv,只有當遇到無法確定原編碼是何種編碼,或者iconv轉(zhuǎn)化后無法正常顯示時才用mb_convert_encoding 函數(shù)

.
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.

$str = mb_convert_encoding($str, "UCS-2LE", "JIS, eucjp-win, sjis-win");

$str = mb_convert_encoding($str, "EUC-JP', "auto");

例子:
$content = iconv("GBK", "UTF-8", $content);
$content = mb_convert_encoding($content, "UTF-8", "GBK");

相關(guān)文章

最新評論