Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if there is a space in a GET or POST key?

Tags:

php

In PHP if I have the following script:

var_dump($_REQUEST);

How can I differentiate the following requests:

GET /foo?hello%20dude=cool
GET /foo?hello_dude=cool

they both print:

array(1) { ["hello_dude"]=> string(4) "cool" }

since key names are not allowed to have spaces? Do I have to manually parse the POST data as well as the GET data or is there an easier way?

like image 629
chacham15 Avatar asked Nov 10 '22 03:11

chacham15


1 Answers

I think you are going to have to bypass PHP's automatic parsing of the query string and do it yourself.

You can get the full request URI by checking $_SERVER['REQUEST_URI']. From there, you can split on the first question mark ?, then split on ampersand &, then split each by =. There may also be a handy regex solution.

like image 75
Brad Avatar answered Nov 12 '22 18:11

Brad