PHP determines page input character encoding method_PHP tutorial

WBOY
Release: 2016-07-13 10:54:36
Original
795 people have browsed it

php tutorial to determine page input character encoding method

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;
}

}
?>

However, some friends said that the mb_detect_encoding function does not support gbk and only supports utf-8, utf-7, ascii, euc-jp, sjis, eucjp-win, sjis-win, jis, iso-2022-jp and iso-8859 -*
You can test it, I haven’t tested it.

/* 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

Recommend an article http://www.bKjia.c0m/phper/php-cy/36263.htm

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632312.htmlTechArticlephp tutorial to determine the page input character encoding method?php function convtoutf8($str) { if( mb_detect_encoding($str, utf-8, iso-8859-1, gbk)!=utf-8 ) { return iconv(gbk,utf-8,$str); } else {...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template