多变量成1的网址 [英] Multiple Variables into 1 in a URL

查看:105
本文介绍了多变量成1的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待有跨在一个URL传递的参数列表。

I am looking to have a list of arguments passed across in an a URL.

$url['key1']=1;
$url['key2']=2;
$url['key3']=3;
$url['key4']=4;
$url['key5']=5;
$url['key6']=6;
$url['key7']=7;

请注意我试图在URL中1 GET变量传递这一点。我知道这会更好地完成键1 = 1&放大器;键2 = 2及。KEY3 = 3 ......等,但对于那些过于复杂,试图解释他们无法在这种格式的原因。

Please Note I am trying to pass this in the URL in 1 GET variable. I know this would be better done by ?key1=1&key2=2&key3=3...etc but for reasons that are too complicated to try and explain they can't be in this format.

任何建议我可以如何数组转换成的东西,可以在URL字符串1 GET VAR?

Any suggestions how I can convert this array into something that can be passed as 1 get var in a URL string?

先谢谢了。

推荐答案

尝试 http_build_query

$url['key1']=1;
$url['key2']=2;
$url['key3']=3;
$url['key4']=4;
$url['key5']=5;
$url['key6']=6;
$url['key7']=7;

echo http_build_query($url);
//echos key1=1&key2=2&key3=3&key...

它所做的使用键是转换一个数组成一个查询字符串,并自动处理URL编码的。

What it does is converting an array into a query string using the keys and automatically takes care of url-encoding.

修改

刚刚看了你的,它应该是只有一个变量的附加要求。所以,请不要介意这个答案。
如果你的问题是正确的编码,虽然你可能想给这个闯闯。

Just read your additional requirement that it should be just one variable. So nevermind this answer. If your problem was the proper encoding though you might want to give this another try.

希望有所帮助。

这篇关于多变量成1的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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