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; } ?> Link to comment https://forums.phpfreaks.com/topic/205042-run-only-if-url-is-available/ 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 } Link to comment https://forums.phpfreaks.com/topic/205042-run-only-if-url-is-available/#findComment-1073382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.