dongpeixiong5943 2013-03-31 22:26
浏览 16
已采纳

使用php解析来自api url调用的xml返回结果时出错

what I am missing here? all I get returned is "Location: 0"

ini_set("user_agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");

$url = "http://ebird.org/ws1.1/data/notable/region/recent?rtype=subnational1&r=US-AZ";

$xml = simplexml_load_file($url);

$locname = $xml->response->result->sighting->loc-id;

echo "Location: ".$locname . "<br/>";
  • 写回答

1条回答 默认 最新

  • douxing6434 2013-03-31 22:55
    关注


    the probelem is with the "-" because php think that you want to subtract id from $xml->response->result->sighting->loc

    the solution is to change :

    $locname = $xml->response->result->sighting->loc-id;
    

    to

    $locname = $xml->result[0]->sighting[0]->{'loc-id'};
    

    it work with me

    i hope this help you

    note : i delete response node because it's the root and i choose the first elemet because the file containe many nodes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据