2

I'm truing to parse arguments like http://localhost/img/ module/border.php?type,colorScheme,template. How to parse it by $_GET?

print_r($_GET); outputs Array ( [type,colorScheme,template] => )

3
  • echo explode('?',"localhost/img/module/… Commented May 19, 2017 at 10:03
  • 1
    "outputs Array ( [type,colorScheme,template] => )" ... well, yes ... that's what you've sent - what were you expecting? Commented May 19, 2017 at 10:04
  • I just did not know about key(). Commented May 19, 2017 at 10:16

3 Answers 3

5

Try:

$args = explode(",", key($_GET));
Sign up to request clarification or add additional context in comments.

Comments

0

Use $_SERVER['QUERY_STRING'] , it contains the data that you are looking for.
After that, just explode this like explode(',',$_SERVER['QUERY_STRING']).

OUTPUT

Array
(
    [0] => type
    [1] => colorScheme
    [2] => template
)

Comments

0

What you wrote in $_GET is 1 variable.
To separate multiple $_GET variables, use &.

http://localhost/img/module/border.php?type&colorScheme&template

To assign values write

?type=sometype&colorScheme=somecolor&template=sometemplate

If you really need/want to send 1 $_GETvariable as you wrote, use explode() which need the delimiter and the string to split:

explode(",", key($_GET));

PHP.net - explode
PHP.net - key

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.