亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從xml獲取數據?

如何從xml獲取數據?

PHP
白衣染霜花 2022-09-03 10:48:21
我正在嘗試從此 XML 獲取天氣數據:https://www.yr.no/sted/Norge/Vestland/Bergen/Bergen/varsel.xml我想這樣顯示:我不知道從哪里開始。    $url = ('');    function Feed($url) {      $feed = simplexml_load_file($url) or die('Can not connect to server');      $result = array();      foreach ($feed->channel->item as $content) {          array_push($result, $content);      }    }    ?>找到了一個例子^,但沒有讓它工作...相當沒有經驗,任何幫助都是值得贊賞的。
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

主要部分是按照鏈接頁面中顯示的 XML 從您返回的內容中提取正確的部分 - 以下代碼提取所需的大部分詳細信息。


$feed = simplexml_load_file($url) or die('Can not connect to server');

$result = array();

foreach ($feed->forecast->tabular->time as $content) {

    array_push($result, [ "from" => (string)$content['from'], 

        "to" => (string)$content['to'],

        'symbol' => (string)$content->symbol['name'],

        'temperature' => (string)$content->temperature['value'],

        'windDirection' => (string)$content->windDirection['code'],

        'windSpeed' => (string)$content->windSpeed['mps'],

    ]);

}

你如何呈現它們現在取決于你。


查看完整回答
反對 回復 2022-09-03
  • 1 回答
  • 0 關注
  • 99 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號