0

I'm Reading many rss feed and store these data in database in my site. for this I'm using

 <?php
      include_once 'db.php';
     $url=array(
     'http://rss.cnn.com/rss/edition_us.rss','http://feeds.cbsnews.com/CBSNewsWorld'
      ...and many other);

       foreach($url as $key => $value){

       $homepage = file_get_contents('$key[$value]');

         $movies = new SimpleXMLElement($homepage);
         echo '<pre>';
          foreach($movies->channel->item as $opt){
     $title= $opt->title;
          $tittle=mysql_real_escape_string($title);
            $link=$opt->link;
            $links=mysql_real_escape_string($link);
          $des=$opt->description;

        $dess=mysql_real_escape_string($des);

        $sql="INSERT INTO store_feed (title, link, description)
        VALUES ('$tittle','$links','$dess')";

         $result=mysql_query($sql) or die('Error, insert query failed');

        }
          }
        if(isset($result)){
echo "submt successful";
         }

         ?>

but it stored only a single URL value..please give me a solution.

1
  • $homepage = file_get_contents('$key[$value]'); - $key[$value] is not the right way to get url from the array. just use $value. Commented Nov 4, 2011 at 10:21

1 Answer 1

1

My edited code, which works as I mentioned in the comment.

<?php

$url=array('http://rss.cnn.com/rss/edition_us.rss', 'http://feeds.cbsnews.com/CBSNewsWorld');

foreach($url as $value){
    $homepage = file_get_contents($value);
    $movies = new SimpleXMLElement($homepage);

    foreach($movies->channel->item as $opt){
        # print_r($opt); // for debugging

        $title = $opt->title;
        $link = $opt->link;
        $description = $opt->description;

        echo 'title: ' .$title. ' - description: ' .$description. ' - link: ' .$link.'<br/><br/><br/>';
    }
}

?>
Sign up to request clarification or add additional context in comments.

1 Comment

Edited my Answer, which works perfectly and shows every movie the rss provides. You have to add the db stuff again, which shouldn't be a big problem, I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.