Php 在读取rss提要时使用数组

Php 在读取rss提要时使用数组,php,xml,rss-reader,Php,Xml,Rss Reader,我正在阅读许多rss提要,并将这些数据存储在我网站的数据库中。我用这个 <?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){

我正在阅读许多rss提要,并将这些数据存储在我网站的数据库中。我用这个

 <?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";
         }

         ?>
channel->item as$opt){
$title=$opt->title;
$title=mysql\u real\u escape\u字符串($title);
$link=$opt->link;
$links=mysql\u real\u escape\u字符串($link);
$des=$opt->description;
$dess=mysql\u real\u escape\u字符串($des);
$sql=“插入存储\u提要(标题、链接、说明)
值(“$title”、“$links”、“$dess”)”;
$result=mysql_query($sql)或die('Error,insert query failed');
}
}
如果(isset($result)){
回声“submt成功”;
}
?>

但是它只存储了一个URL值。请给我一个解决方案。

我编辑的代码,正如我在评论中提到的

channel->item as$opt){
#打印($opt);//用于调试
$title=$opt->title;
$link=$opt->link;
$description=$opt->description;
回显'title:'.$title'.-description:'.$description'.-link:'.$link'.


<?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/>';
    }
}

?>
} } ?>
$homepage=文件获取内容(“$key[$value]”)
-
$key[$value]
不是从数组获取url的正确方法。只需使用
$value
。编辑我的答案,它可以完美地显示rss提供的每一部电影。你必须再次添加db,我认为这应该不是什么大问题。