I'm using PHP to output our XML sports scores, in this example men's basketball. The page currently displays our opponents' names followed by the score and date. There are also XML attributes for home team and away team (for example, Oregon State at Stanford is: hc="stan" vc="orst").
My question is, instead of displaying only the opponents' name, i.e. "Oregon State", is it possible to display "vs Oregon State" if Oregon State is the away team OR display "at Oregon State" if Oregon State is the home team.
Here is my page, XML 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)
{
// Only output if complete
if(!empty($event_date->event['vn']) && !empty($event_date->event['hn']) && !empty($event_date->event['vs']) && !empty($event_date->event['hs']))
{
// Only show opponents' name
$name = ($event_date->event['vc'] == 'stan') ? $event_date->event['hn'] : $event_date->event['vn'];
echo '<li>';
echo '<h3>', $name, '</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>';
}
}
?>