我想從xml獲取數據,但遇到問題。無法從xml提取數據
我已創建簡單的代碼,但我不認爲他們會好..
<?php
$cricapi = 'http://synd.cricbuzz.com/j2me/1.0/livematches.xml';
function followers($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($data);
$mthType = $xml->match['type'];
if ($mthType == "ODI")
{
$match = $xml->match['mchDesc'];
return $match;
}
}
?>
,並呼籲爲
<?php echo $match = followers($cricapi); ?>
,但我無法獲取結果。
請幫我解決這個問題。我試圖做一個類似http://www.hamariweb.com/
請幫我解決這個問題..謝謝大家
確切的問題是什麼? 「但我無法取得結果」不是一個具體問題。 – jli
請嘗試運行此腳本..我應用條件,如果類型== ODI然後提取匹配說明,但該腳本只檢查第一種類型,不要再運行..即使我嘗試foreach循環:( – Muzammil
)你嘗試使用data_is_url標誌而不是curl嗎?嘗試'$ xml = new SimpleXMLElement($ url,0,true);'只用於檢索xml。 – Sgoettschkes