体育比分 XML:如果离开,则回显“at”;如果在家,则回显“vs”

发布于 2024-11-07 00:48:29 字数 1429 浏览 2 评论 0原文

我使用 PHP 输出 XML 体育比赛成绩,在本例中是男子篮球。该页面当前显示对手的姓名,后面是比分和日期。还有主队和客队的 XML 属性(例如,斯坦福大学的俄勒冈州立大学是:hc="stan" vc="orst")。

我的问题是,如果俄勒冈州立大学是客队,是否可以显示“对俄勒冈州立大学”,或者如果俄勒冈州立大学是主队,则可以显示“在俄勒冈州立大学”,而不是只显示对手的名字,即“俄勒冈州立大学” 。

这是我的页面XML 和代码:

<?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>';
    }
}   
?>

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>';
    }
}   
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-11-14 00:48:29

$介词 = ($event_date->event['vc'] == 'stan') ? 'vs' : '在';

然后在团队名称前使用 $preposition

$preposition = ($event_date->event['vc'] == 'stan') ? 'vs' : 'at';

and then use $preposition before the team name.

缱倦旧时光 2024-11-14 00:48:29

也许是这样的?

if($name == $event_date->event['vs']) {
   // vs
} else {
   // at
}

或者

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'];

$playing_location = 'at'; // default
if($name == $event_date->event['vs']) {
   $playing_location = 'vs';
} 

echo '<li>';
    echo '<h3>', $name, '</h3>';
    echo '<p><strong>', $event_date->event['vn'], ' ', $event_date->event['vs'], $playing_location, $event_date->event['hn'], ' ', $event_date->event['hs'], '</strong></p>';
    echo '<p>', date('F j, Y', strtotime($event_date['date'])), '</p>';
echo '</li>';
}

Something like this maybe?

if($name == $event_date->event['vs']) {
   // vs
} else {
   // at
}

or

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'];

$playing_location = 'at'; // default
if($name == $event_date->event['vs']) {
   $playing_location = 'vs';
} 

echo '<li>';
    echo '<h3>', $name, '</h3>';
    echo '<p><strong>', $event_date->event['vn'], ' ', $event_date->event['vs'], $playing_location, $event_date->event['hn'], ' ', $event_date->event['hs'], '</strong></p>';
    echo '<p>', date('F j, Y', strtotime($event_date['date'])), '</p>';
echo '</li>';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文