从包含[]的参数中获取查询字符串值

时间:2016-07-18 21:44:18

标签: php

我需要从查询字符串中获取值,但这是一个特殊条件。我有以下网址:

domain.com?custom_field[email]=test@test.net

但是我得到了这种格式的网址

domain.com?custom_field%5Bemail%5D=test@test.net

我尝试使用通用$_GET['custom_field[email]'];,但它不起作用。

我也尝试过:

urldecode($_GET['custom_field[email]']);

但它也不起作用。任何人都可以告诉我如何才能得到解决方案。

1 个答案:

答案 0 :(得分:0)

如果您的表单如下所示:

<form>
  <input type="email" name="custom_field[email]"/>
  <input type="submit"/>
</form>

并且您提交了test@example.com,那么您的网址将如下所示:

http://localhost/file.php?custom_field%5Bemail%5D=test%40example.com

您可以看到数据的样子:

<?php
print_r($_GET);

将显示:

Array
(
    [custom_field] => Array
        (
            [email] => test@example.com
        )

)

所以你可以用以下方式专门引用该实体:

echo $_GET['custom_field']['email'];
相关问题