Only two kinds of coding in the case, ask my brother I this function safe?

Source: Internet
Author: User
Is there only two kinds of coding in case I am safe with this function?
In the case of only GBK and utf-8 two kinds of coding, have the following function to determine whether the encoding format is safe?
PHP Code
  
   function checkencoding ($str)   {     $s = json_encode ($str);    $c = substr ($s, 0,7);    if ($c = = ' "\ufeff ') return ' utf-8 ';    


------Solution--------------------
How could this be the right one?
abcde0123456789 in the case of GBK and Utf-8, the byte code is exactly the same
------Solution--------------------
Unsafe, even Notepad has a BOM head trap.

In fact, it's not safe to use any of your options.
------Solution--------------------
mb_check_encoding function not?
------Solution--------------------
Csdn do bad enough, want to edit the post is not.
Enclosed is a link found: http://stackoverflow.com/questions/1037363/how-to-check-the-charset-of-string
------Solution--------------------
discuss

Csdn do bad enough, want to edit the post is not.
Enclosed is a link found: http://stackoverflow.com/questions/1037363/how-to-check-the-charset-of-string
  • 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.