There are only two types of codes. could you tell me how secure this function is?

Source: Internet
Author: User
If there are only two types of codes, is this function safe? If only gbk and UTF-8 are supported, can we use the following function to determine whether the encoding format is secure? PHPcodefunctioncheckEncoding ($ str) {$ sjson_encode ($ str); $ csubstr ($ s,); if ($ c & quot; ufe only supports two types of encoding, is this function safe?
If only gbk and UTF-8 are supported, can we use the following function to determine whether the encoding format is secure?
PHP code
  function checkEncoding($str)   {     $s = json_encode($str);    $c = substr($s,0,7);    if($c == '"\ufeff') return 'utf-8';    return 'gbk';} 


------ Solution --------------------
How can this be true?
Abcde0123456789 in the case of gbk and UTF-8, the byte code is exactly the same
------ Solution --------------------
Unsafe. Even notepad has a bom header trap.

In fact, you are not safe to use any solution.
------ Solution --------------------
Does the mb_check_encoding function work?
------ Solution --------------------
Csdn is poor enough to edit posts.
Attached a connection found: http://stackoverflow.com/questions/1037363/how-to-check-the-charset-of-string
------ Solution --------------------
Discussion

Csdn is poor enough to edit posts.
Attached a connection 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.