首頁 >php教程 >php手册 >php判断页面输入字符编码方法

php判断页面输入字符编码方法

WBOY
WBOY原創
2016-06-13 09:55:11843瀏覽

php教程判断页面输入字符编码方法

function convtoutf8($str)
{
if( mb_detect_encoding($str,"utf-8, iso-8859-1, gbk")!="utf-8" )
{

return  iconv("gbk","utf-8",$str);

}
else
{
return $str;
}

}
?>

不过有朋友说,mb_detect_encoding函数不支持gbk只支持utf-8,utf-7,ascii,euc-jp,sjis,eucjp-win,sjis-win,jis,iso-2022-jp和iso-8859-*
各位可以测试,我没测试过。

/* detect character encoding with current detect_order */
echo mb_detect_encoding($str);

/* "auto" is expanded according to mbstring.language */
echo mb_detect_encoding($str, "auto");

/* specify encoding_list character encoding by comma separated list */
echo mb_detect_encoding($str, "jis, eucjp-win, sjis-win");

/* use array to specify encoding_list  */
$ary[] = "ascii";
$ary[] = "jis";
$ary[] = "euc-jp";
echo

推荐一篇文章 http://www.bKjia.c0m/phper/php-cy/36263.htm

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn