When crawling Web pages in PHP, you often need to encode the URL, and then use two functions
mb_detect_encoding - detects the encoding of a character.
mb_convert_encoding - encoding of converted characters
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php /* 使用当前的 detect_order 来检测字符编码 */ echo mb_detect_encoding(
$str
); /* "auto" 将根据 mbstring.language 来扩展 */ echo mb_detect_encoding(
$str
,
"auto"
);
/* 通过逗号分隔的列表来指定编码列表 encoding_list */ echo mb_detect_encoding(
$str
,
"JIS, eucjp-win, sjis-win"
);
/* 使用数组来指定编码列表 encoding_list */ $ary
[] =
"ASCII"
; $ary
[] =
"JIS"
; $ary
[] =
"EUC-JP"
; echo mb_detect_encoding(
$str
,
$ary
); ?>
|
<?PHP/*convert internal code to SJIS*/$str= Mb_convert_encoding ($str, "SJIS");/*convert EUC-JP to UTF-7*/$str= Mb_convert_encoding ($str, "UTF-7", "EUC-JP");/*Auto-detect encoding from JIS, Eucjp-win, Sjis-win, and convert str to Ucs-2le*/$str= Mb_convert_encoding ($str, "Ucs-2le", "JIS, Eucjp-win, Sjis-win");/*"Auto" expands to "Ascii,jis,utf-8,euc-jp,sjis"*/$str= Mb_convert_encoding ($str, "EUC-JP", "Auto");?>
Original http://cn2.php.net/manual/zh/function.mb-convert-encoding.php