I’m using this little PHP function that I wrote to make calls to my master database:
$db_request = curl_init(DB_ROOT.'/action/register.php'); curl_setopt($db_request, CURLOPT_HEADER, 0); curl_setopt($db_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($db_request, CURLOPT_POSTFIELDS, http_build_query($variables)); $db_response = curl_exec($db_request); curl_close ($db_request); parse_str($db_response, $information);
On register.php I use the following to respond:
echo http_build_query(array( 'test1'=>'value1', 'test2'=>'value2', 'test3'=>'value3' ));
My problem comes when trying to retrieve the first index of any given response. I can use var_dump($information)
and will receive array(3) { ["test1"]=> string(6) "value1" ["test2"]=> string(6) "value2" ["test3"]=> string(6) "value3" }
. However, when I try to echo $information['test1']
, I receive this: Notice: Undefined index: test1 in...
.
Echoing anything other than the first index doesn’t give me this problem.
Does anyone have any thoughts?
Advertisement
Answer
parse_str
return type is void
Update your code
parse_str($db_response, $information);