Zekfad
Zekfad

Reputation: 179

PHP: Parse unnamed arguments from url

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] => )

Upvotes: 2

Views: 128

Answers (3)

AymDev
AymDev

Reputation: 7609

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

Upvotes: 0

Marc Anton Dahmen
Marc Anton Dahmen

Reputation: 1091

Try:

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

Upvotes: 5

gaganshera
gaganshera

Reputation: 2639

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
)

Upvotes: 0

Related Questions