Php judgment page input character encoding method _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php determines the encoding of the input characters on the page. In the php Tutorial, how does one determine the encoding of the input characters on the page? Phpfunctionconvtoutf8 ($ str) {if (mb_detect_encoding ($ str, UTF-8, ISO-8859-1, gbk )! UTF-8) {returniconv (gbk, UTF-8, $ str);} else {php Tutorial judgment 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;
}

}
?>

But some friends said, mb_detect_encoding function does not support gbk only support UTF-8, UTF-7, ascii, euc-jp, sjis, eucjp-win, sjis-win, jis, ISO-2022-JP and ISO-8859 -*
You can test it. I have never 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

Http://www.bKjia. c0m/phper/php-cy/36263.htm recommended article

Why? Php function convtoutf8 ($ str) {if (mb_detect_encoding ($ str, UTF-8, ISO-8859-1, gbk )! = Utf-8) {return iconv (gbk, UTF-8, $ str);} else {...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.