PHP URL 编码/解码 [英] PHP URL Encoding / Decoding
问题描述
我使用了此问题所接受的解决方案 用于通过 id 加密,例如 /index.php?id=3 .问题是我无法将加密值作为 url 发送,例如 /index.php?id=dsf13f3343f23/23=.因为有时它会在 url 中包含奇怪的字符,例如注意最后的 =
符号
I used the solution accepted for this question for encrypting by id for example in /index.php?id=3 . The problem is I cannot send the encrypted value as an url, example /index.php?id=dsf13f3343f23/23=. Because sometimes it will have weird characters in the url e.g. notice the =
sign in the end
推荐答案
URL 中传递的值中的奇怪字符 应该使用 urlencode(
).
The weird characters in the values passed in the URL should be escaped, using urlencode(
).
例如下面的代码部分:
For example, the following portion of code :
echo urlencode('dsf13f3343f23/23=');
会给你:
dsf13f3343f23%2F23%3D
作为 URL 参数工作正常.
Which works fine, as an URL parameter.
如果你想用几个参数构建一个查询字符串,看看 http_build_query()
函数.
例如:
echo http_build_query(array(
'id' => 'dsf13f3343f23/23=',
'a' => 'plop',
'b' => '$^@test',
));
会给你:
id=dsf13f3343f23%2F23%3D&a=plop&b=%24%5E%40test
这个函数处理转义和连接参数本身;-)
This function deals with escaping and concatenating the parameters itself ;-)
这篇关于PHP URL 编码/解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!