PHP $_REQUEST 作为数组
我有一个搜索表单,我想将搜索词作为数组 $_REQUEST ,这样我就可以列出每个搜索词,将每个搜索词包装在一个跨度中以进行样式设置。我该怎么做?
编辑:这是请求的代码。
<form action="http://localhost/wordpress" id="search" method="get">
<input type="text" size="30" id="s" name="s" value="Type and hit enter" onfocus="javascript:this.value='';" onblur="javascript:this.value='Type and hit enter';"/>
<br/>
<input type="submit" value="Search"/>
</form>
更新:谢谢大家的回复。我将使用爆炸,它看起来相当简单。而且这个名字听起来很酷^^
I have a search form, I want to $_REQUEST the search terms as an array so I can list each search term out, wrapping each term in a span for styling. How do I do that?
Edit: Here's the code requested.
<form action="http://localhost/wordpress" id="search" method="get">
<input type="text" size="30" id="s" name="s" value="Type and hit enter" onfocus="javascript:this.value='';" onblur="javascript:this.value='Type and hit enter';"/>
<br/>
<input type="submit" value="Search"/>
</form>
Update: Thanks guys for the responses. I'll use explode, it seems fairly straightforward. Plus the name sounds cool ^^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在表单中:
在表单处理器中:
In the form:
In the form processor:
如果您希望用户在单独的输入控件中输入多个搜索词,上述答案应该会有所帮助。但是,您的示例表单让我想知道您是否只想使用一个搜索短语输入文本框。如果是这样,这可能就是您正在寻找的:
If you want the user to enter multiple search terms in separate input controls, the above answers should be helpful. However, your example form leads me to wonder if you want to use only one search phrase input text box. If that's so, this might be what you're looking for:
我这样做了......
传递一个数组(它实际上只是 PHP 的一个字符串):
然后在脚本中,只需分解字符串:
也许不正是您正在寻找的东西。
I did it this way..
Passing an array (it's really just a string to PHP):
Then in the script, just explode the string:
Maybe not exactly what you're looking for.
我认为您希望用户有一个条目输入,然后您希望将其拆分为一组单独的搜索词。
将您的输入拆分为空格(将连续的空格字符视为一个)以派生单独的术语。
例如:
当然,不要忘记在使用输入之前正确过滤和转义输入。
I figure you wish the user to have one single entry input, which you then wish to split into an array of separate search terms.
Split your input on whitespace (treating consecutive whitespace characters as one) to derive separate terms.
For example :
Ofcourse do not forget to properly filter and escape the input before you use it.
如果您想用空格符号分隔搜索词,只需尝试以下代码:
If you want break your search terms by space symbols just try this code:
在 HTML 表单元素中,您可以将名称分配给一个数组,如下所示:
然后,当您在提交后处理表单时,您可以执行以下操作:
In your HTML form element you can assign the name to an array, like this:
then when you deal with the form after submittion you can do something like:
以下是将表单结果作为数组传递的更多详细信息:
http://us.php.net/manual/ zh/faq.html.php#faq.html.arrays
Here's more details on passing in form results as an array:
http://us.php.net/manual/en/faq.html.php#faq.html.arrays