PHP URL编码/解码 [英] PHP URL Encoding / Decoding

查看:131
本文介绍了PHP URL编码/解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了接受此问题用于在/index.php?id=3 中通过ID进行加密.问题是我无法将加密的值作为URL发送,例如/index.php?id=dsf13f3343f23/23 = .因为有时它在网址中会有奇怪的字符,例如注意最后的=符号

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中传递的值中的奇怪字符应该使用

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() 功能.


And if you want to build aquery string with several parameters, take a look at the http_build_query() function.

例如:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆