使用 PHP 从查询字符串中获取数组参数
(注意:这是上一个问题的后续,如何在查询字符串中传递数组?,其中我询问了在查询字符串中传递数组的标准方法。)
我现在有一些 PHP 代码需要使用表示查询字符串-查询字符串数组格式是什么样的PHP 能识别吗?我需要做什么特殊的事情来检索该数组吗?
以下似乎不起作用:
查询字符串:
?formparts=[a,b,c]
PHP:
$myarray = $_GET["formparts"];
echo gettype($myarray)
结果:
string
(NOTE: This is a follow up to a previous question, How to pass an array within a query string?, where I asked about standard methods for passing arrays within query strings.)
I now have some PHP code that needs to consume the said query string- What kind of query string array formats does PHP recognize, and do I have to do anything special to retrieve the array?
The following doesn't seem to work:
Query string:
?formparts=[a,b,c]
PHP:
$myarray = $_GET["formparts"];
echo gettype($myarray)
result:
string
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的查询字符串应该如下所示:
Your query string should rather look like this:
如果您正在处理查询字符串,您将查看
$_GET
变量。这将包含上一个问题中?
之后的所有内容。所以你要做的几乎与另一个问题相反。
对于每个变量依此类推。我必须在这里给你一个完整的警告,你必须检查
$_GET
变量的内容以确保它是正常的。否则,您的网站将面临被泄露的风险。If you're dealing with a query string, you are looking at the
$_GET
variable. This will contain everything after the?
in your previous question.So what you will have to do is pretty much the opposite of the other question.
and so on for each variable. I must give you a full warning here, you MUST check what comes through the
$_GET
variable to make sure it is sane. Otherwise you risk having your site compromised.