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