开发者

Output XML opponent's name only, regardless of home or away

I'm using PHP to output data from a sports XML file (in this example it's men's basketball). The XML file features home name ("hn") and visitor name ("vn"), for example the latest score's h3 is "Oregon State vs Stanford."

My question is, how can the h3 display only the opponent's name, regardless of whether they're home or away (in other words, it shouldn't say "Stanford", just the opponent's name, i.e. "Oregon State").

Here's my page and code:

    <?php
    $xml = simplexml_load_file('http://www.gostanford.com/data/xml/events/m-baskbl/2010/index.xml');

    // Reverse chronological order
    $xmlArray = array();
    foreach ($xml as $event_date) $xmlArray[] = $event_date;
    $xmlArray = array_reverse($xmlArray);

    foreach ($xmlArray as $event_date) {
        if(!empty($event_date->event['vn']) && !empty($event_date->event['hn']) && !empty($event_date->event['vs']) && !empty($event_date->event['hs']))
        {
                echo '<li>';
                    echo '<h3>开发者_JAVA百科', $event_date->event['vn'], ' vs ', $event_date->event['hn'], '</h3>';
                    echo '<p><strong>', $event_date->event['vn'], ' ', $event_date->event['vs'], ' - ', $event_date->event['hn'], ' ', $event_date->event['hs'], '</strong></p>';
                    echo '<p>', date('F j, Y', strtotime($event_date['date'])), '</p>';
                echo '</li>';
        }
    }   
    ?>

Thanks for your help!


Change

 echo '<li>';
      echo '<h3>', $event_date->event['vn'], ' vs ', $event_date->event['hn'], '</h3>';

to

 $name = ($event_date->event['vc'] == 'stan') ? $event_date->event['hn'] : $event_date->event['vn'];
 echo '<li>';
      echo '<h3>', $name, '</h3>';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜