mb_convert_encoding( $str, $encoding1,$encoding2 )
$str,要轉換編碼的字串
$encoding1,目標編碼,如utf-8,gbk,大小寫均可
$encoding2,原編碼,如utf-8,gbk,大小寫均可
執行個體1
代碼如下 |
複製代碼 |
<?php $str='電影618:http://www.111cn.net'; echo mb_convert_encoding($str, "UTF-8"); //編碼轉換為utf-8 ?> |
執行個體2
代碼如下 |
複製代碼 |
<?php $str='電影618:http://www.111cn.net'; echo mb_convert_encoding($str, "UTF-8", "GBK"); //已知原編碼為GBK,轉換為utf-8 ?> |
執行個體3
代碼如下 |
複製代碼 |
<?php $str='電影618:http://www.111cn.net'; echo mb_convert_encoding($str, "UTF-8", "auto"); //未知原編碼,通過auto自動檢測後,轉換編碼為utf-8 ?> |
php.net網站執行個體
代碼如下 |
複製代碼 |
<?php /* Convert internal character encoding 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, 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"); ?> |