>  기사  >  백엔드 개발  >  php的urlencode和rawurlencode对空格编码的区别

php的urlencode和rawurlencode对空格编码的区别

WBOY
WBOY원래의
2016-06-06 20:51:441423검색

我最近在使用urlencode对字符串进行编码时发现它将空格字符串编码为了+,但是如果你用rawurlencode来编码,空格字符串就会变为%20。而且在浏览器里输入空格后,它都会将其转化为%20

php的urlencode和rawurlencode对空格编码的区别

这两者有什么区别吗?后端服务器在接受这两种编码请求时会有和不同呢?

我试着将http://zh.wikipedia.org/wiki/Internet%20Explorer%207网址替换为http://zh.wikipedia.org/wiki/Internet+Explorer+7,发现就无法识别了。

回复内容:

我最近在使用urlencode对字符串进行编码时发现它将空格字符串编码为了+,但是如果你用rawurlencode来编码,空格字符串就会变为%20。而且在浏览器里输入空格后,它都会将其转化为%20

php的urlencode和rawurlencode对空格编码的区别

这两者有什么区别吗?后端服务器在接受这两种编码请求时会有和不同呢?

我试着将http://zh.wikipedia.org/wiki/Internet%20Explorer%207网址替换为http://zh.wikipedia.org/wiki/Internet+Explorer+7,发现就无法识别了。

From Wikipedia (emphasis and link added):

When data that has been entered into HTML forms is submitted, the form field names and values are encoded and sent to the server in an HTTP request message using method GET or POST, or, historically, via email. The encoding used by default is based on a very early version of the general URI percent-encoding rules, with a number of modifications such as newline normalization and replacing spaces with "+" instead of "%20". The MIME type of data encoded this way is application/x-www-form-urlencoded, and it is currently defined (still in a very outdated manner) in the HTML and XForms specifications.

来源:
http://stackoverflow.com/questions/16...

其他参考:
http://stackoverflow.com/questions/12...

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.