Jump to content

Run only if URL is available


OhTheNoes

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.