1

Sorry for the basic question, but I'm new to PHP.

I am using curl in php to access a record from a database. Everything works fine, in the end I am creating a variable called 'result'. My question is how can I access the xcoord and ycoord values that are within the result variable?

my curl:

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $result = curl_exec($ch);
  curl_close($ch);

the result of echo $result; :

{"time":0.041,"total_rows":1,"rows":[{"name":" test ","xcoord":" 13.307580499999972 ","ycoord":" 52.4212494"}]} 

Thanks for the help in advance

1
  • 2
    It has nothing to do with curl. The HTTP request you are doing is returning what seems to be JSON data. Use json_decode() to decode this string into the JSON tree. Commented Mar 14, 2013 at 21:59

1 Answer 1

2

Looks like it's JSON

$decoded = json_decode($result);

echo $decoded->time;
echo $decoded->total_rows;
foreach($decoded->rows as $row) {
   echo $row->name;
   //so on
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.