php更改url的数组格式
我正在做一个奇怪的项目。我对 php 完全陌生,所以到目前为止一直很困难。
我有一个提供数组并发布它的表单:
...
return($keywords);
}
$keywordlist = explode("\r\n", $keywordlist);
foreach($keywordlist as $keyword){
print_r(mixer(strtolower($keyword)));
}
我明白了:
Array ( [0] => one [1] => two [2] => three [3] => four [4] => five [5] => six [6] => ....
但希望它像这样出现:
%28one%2Ctwo%2Cthree%2Cfour%2Cfive%2Csix%29
最终希望能够将其附加到像ask.com搜索这样的网址末尾:
"http://www.ask.com/web?q=(put my keywords here)"
然后导航到那里
理论上,就像我在搜索栏中输入“(一、二、三、四、五、六)”并按 Enter 键。
希望这是有道理的。
I have a weird project I'm working on. I'm totally new to php so it has been a struggle so far.
I have a form that gives an array and posts it:
...
return($keywords);
}
$keywordlist = explode("\r\n", $keywordlist);
foreach($keywordlist as $keyword){
print_r(mixer(strtolower($keyword)));
}
I get this:
Array ( [0] => one [1] => two [2] => three [3] => four [4] => five [5] => six [6] => ....
But would like it to come out like this instead:
%28one%2Ctwo%2Cthree%2Cfour%2Cfive%2Csix%29
Ultimately hope to be able to attach it to the end of a url like ask.com search:
"http://www.ask.com/web?q=(put my keywords here)"
then navigate there
In theory it would be like I typed "(one,two,three,four,five,six)" into the search bar and pressed enter.
Hopefully that makes some sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
像这样的东西:
Something like this:
使用 php implode() 函数。
所以你可以这样做:
现在
$string
将是你所需要的Use the php implode() function.
So you could do this:
Now
$string
will be what you need此代码:
给出此输出:
This code:
Gives this output:
print_r
就是这样打印你的数组的。http://php.net/manual/en/function.print-r.php
如何解决这个问题取决于几个因素。 mixer() 的作用是什么?关键字总是小写吗?如果混频器没有做太多事情并且关键字是小写的,你可以这样做:
如果它是 URL 编码,您可以使用函数
url_encode
而不是像上面那样手动添加编码值。print_r
is what prints your array like this.http://php.net/manual/en/function.print-r.php
How to solve it depends on a few things. What does
mixer()
do? And is the keywords always in lowercase? If mixer doens't do much and the keywords are in lowercase you could do something like:If it's URL encoding you are after you could use the function
url_encode
instead of manually adding encoded values as above.像这样的东西吗?
Something like this?
您可以使用 urlencode 对数组的每个部分进行编码,然后手动将其放入您的 url 中(自己制作一个 url 字符串)。 http://php.net/manual/en/function.urlencode.php
或者您可以使用此函数: http://php.net/manual /en/function.http-build-query.php
You could encode each part of the array using urlencode and then manually put it in your url (making a url string by yourself). http://php.net/manual/en/function.urlencode.php
Or you could use this function instead: http://php.net/manual/en/function.http-build-query.php