2016-04-10 7 views
0

I「ミリアンペア合計PHP初心者とxml to PHPのネストされた配列はどうですか?

はこのXMLを持っている:-)いくつかの助けが必要:

http://pastebin.com/ZSpNPhXH

そしてこのscrypt:

どう
<?php 

// Retrieve XML File 
$file = file_get_contents('livescore-feed.xml'); 

// Parse XML with SimpleXML 
$livescore_data = new SimpleXMLElement($file); 


foreach ($livescore_data->league as $league) { 

    echo "<table class='table table-striped table-bordered table-condensed'>"; 


    echo "<thead><tr><th colspan='6' id='league'>" . $league->attributes()->name . "</th></tr></thead>"; 

    echo "<tbody>"; 
    foreach ($league->match as $match) { 




     $status = $match->attributes()->status; 
     $home = $match->home->attributes()->name; 
     $away = $match->away->attributes()->name; 
     $score = $match->home->attributes()->goals . " - " . $match->away->attributes()->goals; 

     // If match not yet started, there will be a ":" in 'status' attribute 
     if (strpos($match->attributes()->status,':') !== false) { 
      $score = "-"; 
     } 



     echo "<tr><td class='status' id='match'>" . $status . "</td><td id='match' colspan='2'>" . 
      $home . "</td><td class='score' id='match'>" . $score . "</td><td id='match' colspan='2'>" . 
      $away . "</td> 


       </tr>"; 

    } 


    echo "</tbody></table>"; 
} 

>

? 「イベント」を表示/解析する場合も

ご協力いただきありがとうございます。

答えて

0

他のデータを解析するのと同じ方法で!

foreach($livescore_data->league as $league) 
{ 
    (...) 
    foreach($league->match as $match) 
    { 
     (...) 
     #  ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 
     foreach($match->events->event as $event) 
     { 
      echo $event['assist'] . '<br>'; 
      echo $event['player'] . '<br>'; 
      (...) 
     } 
    } 
} 

あなたは$match->events->eventをループを実行するために持っていて、$event[attribute]構文を使用して、各<event>属性を取得することができます。したがって、$event['extra_min']$event['minute']など...

あなたはテーブル構造にコードを適合させるだけです。

関連する問題