只有两种编码的情况下,请教小弟我这个函数安全吗

WBOY
Release: 2016-06-13 12:50:53
Original
849 people have browsed it

只有两种编码的情况下,请问我这个函数安全吗?
在只有gbk和utf-8两种编码的情况下,有下面这个函数判断编码格式是否安全呢?

<br />
function checkEncoding($str)   <br />
{ <br />
	$s = json_encode($str);<br />
	$c = substr($s,0,7);<br />
	if($c == '"\ufeff') return 'utf-8';<br />
	return 'gbk';<br />
} <br />
<br />
Copy after login

------解决方案--------------------
怎么可能这个是对的?
abcde0123456789在gbk 和 utf-8的情况下,字节代码是完全一样的
------解决方案--------------------
不安全,甚至notepad就有个bom头陷阱。

事实上,你采用任何方案都不会安全。
------解决方案--------------------
mb_check_encoding函数不行吗? 
------解决方案--------------------
csdn做的够烂的,想编辑帖子都不行。
附上查到的一个连接:http://stackoverflow.com/questions/1037363/how-to-check-the-charset-of-string
------解决方案--------------------

引用:
csdn做的够烂的,想编辑帖子都不行。
附上查到的一个连接:http://stackoverflow.com/questions/1037363/how-to-check-the-charset-of-string

这好像倒是错怪csdn了
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!