doulongdan2264 2013-03-14 21:57
浏览 8
已采纳

如何从php curl访问结果

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条回答 默认 最新

  • dsam70528 2013-03-14 21:59
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Java,消息推送配置
  • ¥15 Java计划序号重编制功能,此功能会对所有序号重新排序,排序后不改变前后置关系。
  • ¥15 关于哈夫曼树应用得到一些问题
  • ¥15 使用sql server语句实现下面两个实验(需要代码和运行结果截图)
  • ¥20 用web解决,要给我一个完整的网页,符合上述的要求
  • ¥20 求个sql server代码和结果的图 两道题
  • ¥15 银河麒麟操作系统无法使用U盘
  • ¥100 寻找:光电二极管电路设计服务
  • ¥15 YOLOv5改进后的结构图
  • ¥15 全志v3s怎么设置高速时钟,使用的荔枝派zero开发板,串口2需要921600的波特率