OhTheNoes Posted June 17, 2010 Share Posted June 17, 2010 Is it possible to make this function only work if the RSS feed URL is available? That is, so that it won't display an error if the RSS is missing/unavailable? Much thanks in advance for any help! <?php function parseRSS($url) { $feedeed = implode('', file($url)); $parser = xml_parser_create(); xml_parse_into_struct($parser, $feedeed, $valueals, $index); xml_parser_free($parser); foreach($valueals as $keyey => $valueal){ if($valueal['type'] != 'cdata') { $item[$keyey] = $valueal; } } $i = 0; foreach($item as $key => $value){ if($value['type'] == 'open') { $i++; $itemame[$i] = $value['tag']; } elseif($value['type'] == 'close') { $feed = $values[$i]; $item = $itemame[$i]; $i--; if(count($values[$i])>1){ $values[$i][$item][] = $feed; } else { $values[$i][$item] = $feed; } } else { $values[$i][$value['tag']] = $value['value']; } } return $values[0]; } $xml = parseRSS("http://domain.com/feed/"); foreach($xml['RSS']['CHANNEL']['ITEM'] as $item) { $fDate = mb_substr ($item['PUBDATE'],5,11); echo("<p>Last updated: <a href=\"{$item['LINK']}\">"); echo($fDate); echo("</a></p>"); break; } ?> Quote Link to comment Share on other sites More sharing options...
bugcoder Posted June 17, 2010 Share Posted June 17, 2010 before foreach loop on every varialbe add extra check of isset and !empty like if( isset($variable) && !empty($variable)){ foreach loops } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.