Home  >  Article  >  Backend Development  >  php的urlencode有关问题

php的urlencode有关问题

WBOY
WBOYOriginal
2016-06-13 10:15:25966browse

php的urlencode问题
现有如下测试页面

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $name = $_GET['name'];    echo urlencode($name);?>

访问XXX.php?name=数据结构
不同浏览器返回的结果居然不同!
在firefox7和IE9下输出是%CA%FD%BE%DD%BD%E1%B9%B9,而在chrome下输出是 %E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84 !!
为什么在php中都是通过urlencode函数进行处理,得到的结果会是跟浏览器有关系的?

还有一个问题就是我想做一个简单的表单,method为get
但text中是中文的时候,它会自动编码,假设是“数据结构”,编码后的结果又是%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84。这个结果跟javascript的encodeURIComponent处理结果相同。
而我在php端处理是需要得到%CA%FD%BE%DD%BD%E1%B9%B9(也就是php的urlencode)。
请问这样的话要怎么处理?或者这么说,如果是从encodeURIComponent得到的结果,要怎么处理成urlencode结果。

------解决方案--------------------
唔,%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84
这个是乱码后urlencode的结果。转换下编码格式吧。
------解决方案--------------------
探讨
因为你是通过 url 传值的,而浏览器有一个选项“总是以utf-8编码发送”

%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84 是 数据结构 utf-8 编码的 url 编码

%CA%FD%BE%DD%BD%E1%B9%B9 是 数据结构 gbk 编码的 url 编码
Statement:
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