I'm Reading many rss feed and store these data in database in my site. for this I'm using
我正在阅读许多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";
}
?>
but it stored only a single URL value..please give me a solution.
但它只存储了一个URL值。请给我一个解决方案。
1 个解决方案
#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/>';
}
}
?>
#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/>';
}
}
?>