php编码转换函数(iconv mb_convert_encoding)

发布时间:2020-12-31编辑:脚本学堂
本文介绍了php编码转换函数的用法,iconv与mb_convert_encoding函数的例子,有需要的朋友参考下。

一般情况下用 iconv,只有当遇到无法确定原编码是何种编码,或iconv转化后无法正常显示时才用mb_convert_encoding 函数。

1,iconv函数语法 :
 

复制代码 代码示例:
<?php
echo iconv("ISO-8859-1", "UTF-8", "This is a test.");
?>

2,mb_convert_encoding函数语法 :
 

复制代码 代码示例:

<?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");
?>