parse_str on an object instead of global namespace

Go To


Normally using parse_str('name=me&hungry=yes') will make a variable $name and hungry be equal to 'me' and 'yes' respectively.

The problem with using this function is that I'm running it through user input and feel uncomfortable making sure I can't get any attacks because of this, since the variables are being put on the global namespace.

Is there any way to make this functionality only put values into a given variable? For example something like parse_str('name=me&hungry=yes', $obj) will make obj be equal to

array('name' => 'me', 'hungry' => 'yes');
2012-04-03 23:14
by qwertymk
What's wrong with parse_str('name=me&hungry=yes', $obj):? On reading the manual it should work as you would like. The second argument will be passed by reference - 2012-04-03 23:21


Not only for example, but exactly. See parse_str­Docs, especially the examples.

2012-04-03 23:19
by hakre
wow, now I feel foolis - qwertymk 2012-04-03 23:38


The second argument to parse_str() will be an array of the params.

2012-04-03 23:23
by alex



$newarray is the array you can work on from there

2012-04-03 23:43
by Darrell Ding