使用数组读取 RSS feed
我正在阅读许多 rss feed 并将这些数据存储在我网站的数据库中。为此,我正在使用
<?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";
}
?>
,但它只存储了一个 URL 值..请给我一个解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我编辑的代码,正如我在评论中提到的那样工作。
My edited code, which works as I mentioned in the comment.