开发者

PHP if variables are not empty, echo

I'm working with this XML file that has some empty attributes, in which case I want to skip that entire attribute's list item. Unfortunately my code still shows everything, even if one of the attributes are empty. I'm sure there's a simpler (and working) way to do this. Here's my page and code:

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

foreach($xml as $event_date){
    if(isset($event_date->event['vn']) && isset($event_date->event['hn']) && isset($event_date->event['vs']) && isset($event_date->event['hs']))
    { 
        echo '<li>';
        echo '<h3>', $event_date->event['vn'], ' vs ', $event_date->event['h开发者_C百科n'], '</h3>';
        echo '<p><strong>', $event_date->event['local_time'], '</strong></p>';
        echo '<h3>', $event_date->event['vs'], ' - ', $event_date->event['hs'], '</h3>';
        echo '</li>';   
    }
}


Replace your isset with !empty

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜