如何在PHP中正确地对字符串进行URL编码? [英] How to properly URL encode a string in PHP?
本文介绍了如何在PHP中正确地对字符串进行URL编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在搜索页面,您在其中输入搜索查询,并将表单提交到search.php?query=your query
.什么PHP函数是最好的,我应该使用它对搜索查询进行编码/解码?
I'm making a search page, where you type a search query and the form is submitted to search.php?query=your query
. What PHP function is the best and that I should use for encoding/decoding the search query?
推荐答案
对于URI查询,请使用 urlencode
/ urldecode
;对于其他任何内容,请使用 rawurlencode
/ rawurldecode
.
For the URI query use urlencode
/urldecode
; for anything else use rawurlencode
/rawurldecode
.
urlencode
和rawurlencode
之间的区别是
-
urlencode
根据 应用程序/x-www-form-urlencoded (空格用+
编码),而 -
rawurlencode
根据普通的 进行编码百分比编码 (空格用%20
编码).
urlencode
encodes according to application/x-www-form-urlencoded (space is encoded with+
) whilerawurlencode
encodes according to the plain Percent-Encoding (space is encoded with%20
).
这篇关于如何在PHP中正确地对字符串进行URL编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文