Write rss to a file

This function is used for writing rss to a file.

<?php
function rss_to_file($url,$file){
  $rss = simplexml_load_file($url);
 
  if($rss){
    $text = "";
 
    $text .= $rss->channel->title."\r\n \r\n \r\n";
 
    $items = $rss->channel->item;
 
    foreach($items as $item){
        $title = $item->title;
        $link = $item->link;
        $published_on = $item->pubDate;
        $description = $item->description;
 
        $text .= $title."\r\n";
        $text .= $published_on."\r\n";
        $text .= $description."\r\n \r\n";
    }
 
    $handle = fopen($file, 'w');
    fwrite($handle, $text);
    fclose($handle);
  }
 
  return false;
}
 
$url = "http://rubensargsyan.wordpress.com/feed/"; // Rss url
$file = date("Y-m-d").".txt"; // The file
 
rss_to_file($url,$file);
?>

If the rss url is wrong the function return false.

  • Share/Bookmark
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

2 Responses to “Write rss to a file”

  1. Droid says:

    Ruben, what the use of saving any rss into file?

  2. Daniel Hauca says:

    Droid, I think somebody will use it. :)

Leave a Reply

*





Info