user3550203 user3550203 - 4 months ago 12
PHP Question

Get query string value from parameter that contains [ ]

I need to get values from a query string but this is a special condition. I have the following url:

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


But I get the url in this format

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


I tried using generic
$_GET['custom_field[email]'];
but its not working.

I also tried:

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


But its not working either. Can anyone please tip me how can I get solution for this.

Answer

if your form looks like this:

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

and you submit test@example.com, then your url will look like this:

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

you can see what the data looks like with:

<?php
print_r($_GET);

which will display:

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

)

so you can specifically reference the entity with:

echo $_GET['custom_field']['email'];
Comments