Php 到MySQL数据库服务器的Simplepie RSS源
我目前使用的是拉入我的RSS提要,如下面的配置所示。我想将Php 到MySQL数据库服务器的Simplepie RSS源,php,mysql,simplepie,Php,Mysql,Simplepie,我目前使用的是拉入我的RSS提要,如下面的配置所示。我想将$url移动到我的数据库,因为我的网站加载速度太慢。我将每个url作为站点名称的键值对。我希望保持这种关联,因为我使用例如“abc”从我的目录中提取图像,我使用它为每个提要设置样式,正如您在下面的foreach循环中看到的那样 我的问题是,由于我不太清楚数组和表是如何协同工作的,我应该如何重写这个脚本以同样的方式使用数据库 我还应该提到,我已经在MySQL中创建了一个表,其中包含行“id”、“name”和“url”。任何澄清都会有所帮助
$url
移动到我的数据库,因为我的网站加载速度太慢。我将每个url作为站点名称的键值对。我希望保持这种关联,因为我使用例如“abc”从我的目录中提取图像,我使用它为每个提要设置样式,正如您在下面的foreach
循环中看到的那样
我的问题是,由于我不太清楚数组和表是如何协同工作的,我应该如何重写这个脚本以同样的方式使用数据库
我还应该提到,我已经在MySQL中创建了一个表,其中包含行“id”、“name”和“url”。任何澄清都会有所帮助
<?php
require_once('php/autoloader.php');
$feed = new SimplePie();
// Create a new instance of SimplePie
// Load the feeds
$urls = array(
'http://abcfamily.go.com/service/feed?id=774372' => 'abc',
'http://www.insideaolvideo.com/rss.xml' => 'aolvideo',
'http://feeds.bbci.co.uk/news/world/rss.xml' => 'bbcwn',
'http://www.bing.com' => 'bing',
'http://www.bravotv.com' => 'bravo',
'http://www.cartoonnetwork.com' => 'cartoonnetwork',
'http://feeds.cbsnews.com/CBSNewsMain?format=xml' => 'cbsnews',
'http://www.clicker.com/' => 'clicker',
'http://feeds.feedburner.com/cnet/NnTv?tag=contentBody.1' => 'cnet',
'http://www.comedycentral.com/' => 'comedycentral',
'http://www.crackle.com/' => 'crackle',
'http://www.cwtv.com/feed/episodes/xml' => 'cw',
'http://disney.go.com/disneyxd/' => 'disneyxd',
'http://www.engadget.com/rss.xml' => 'engadget',
'http://syndication.eonline.com/syndication/feeds/rssfeeds/video/index.xml' => 'eonline',
'http://sports.espn.go.com/espn/rss/news' => 'espn',
'http://facebook.com' => 'facebook',
'http://flickr.com/espn/rss/news' => 'flickr',
'http://www.fxnetworks.com//home/tonight_rss.php' => 'fxnetworks',
'http://www.hgtv.com/' => 'hgtv',
'http://www.history.com/this-day-in-history/rss' => 'history',
'http://rss.hulu.com/HuluRecentlyAddedVideos?format=xml' => 'hulu',
'http://rss.imdb.com/daily/born/' => 'imdb',
'http://www.metacafe.com/' => 'metacafe',
'http://feeds.feedburner.com/Monkeyseecom-NewestVideos?format=xml' => 'monkeysee',
'http://pheedo.msnbc.msn.com/id/18424824/device/rss/' => 'msnbc',
'http://www.nationalgeographic.com/' => 'nationalgeographic',
'http://dvd.netflix.com/NewReleasesRSS' => 'netflix',
'http://feeds.nytimes.com/nyt/rss/HomePage' => 'newyorktimes',
'http://www.nick.com/' => 'nickelodeon',
'http://www.nickjr.com/' => 'nickjr',
'http://www.pandora.com/' => 'pandora',
'http://www.pbskids.com/' => 'pbskids',
'http://www.photobucket.com/' => 'photobucket',
'http://feeds.reuters.com/Reuters/worldNews' => 'reuters',
'http://www.revision3.com/' => 'revision3',
'http://www.tbs.com/' => 'tbs',
'http://www.theverge.com/rss/index.xml' => 'theverge',
'http://www.tntdrama.com/' => 'tnt',
'http://www.tvland.com/' => 'tvland',
'http://www.vimeo.com/' => 'vimeo',
'http://www.vudu.com/' => 'vudu',
'http://feeds.wired.com/wired/index?format=xml' => 'wired',
'http://www.xfinitytv.com/' => 'xfinitytv',
'http://www.youtube.com/topic/4qRk91tndwg/most-popular#feed' => 'youtube',
);
$feed->set_feed_url(array_keys($urls));
$feed->enable_cache(true);
$feed->set_cache_location('cache');
$feed->set_cache_duration(1800); // Set the cache time
$feed->set_item_limit(1);
$success = $feed->init(); // Initialize SimplePie
$feed->handle_content_type(); // Take care of the character encoding
?>
<?php require_once("inc/connection.php"); ?>
<?php require_once("inc/functions.php"); ?>
<?php include("inc/header.php"); ?>
<?php
// Sort it
$feed_items = array();
// $feed_items is an array
$items = $feed->get_items();
//$items is everything that $items = $feed->get_items(); produces
$urls = array_unique($urls);
// $url = is an empty $
foreach ($urls as $url => $image) {
$unset = array();
$feed_items[$url] = array();
foreach ($items as $i => $item) {
if ($item->get_feed()->feed_url == $url) {
$feed_items[$url][] = $item;
$unset[] = $i;
}
}
foreach ($unset as $i) {
unset($items[$i]);
}
}
foreach ($feed_items as $feed_url => $items) {
if (empty($items)) { ?>
<div class="item element" data-symbol="<?php echo $urls[$feed_url] ?>" name="<?php echo $urls[$feed_url] ?>">
<div class="minimise"><img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/>
<div class="minimise2">
<a href="<?php echo $feed_url; ?>"><h2>Visit <?php echo $urls[$feed_url] ?> now!</h2></a>
</div></div>
<div class="maximise">
<a href="<?php echo $feed_url; ?>"><h2>Visit <?php echo $urls[$feed_url] ?> now!</h2></a>
</div></div>
<?
continue;
}
$first_item = $items[0];
$feed = $first_item->get_feed();
?>
<?php
$feedCount = 0;
foreach ($items as $item) {
$feedCount++;
?>
<div class="item element" " data-symbol="<?php echo $urls[$feed_url] ?>" name="<?php echo $urls[$feed_url] ?>">
<div class="minimise"><strong id="amount"><?php echo ''.$feedCount; ?></strong>
<img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/>
<div class="minimise2"><a href="<?php echo $item->get_permalink(); ?>">
<h2><?php echo $item->get_title(); ?></h2></a>
</div></div>
<div class="maximise"><a href="<?php echo $item->get_permalink(); ?>">
<h2><?php echo $item->get_title(); ?></h2></a><br><p><?php echo $item->get_description(); ?></p>
</div></div>
<?php
}
}
?>
<?php require("inc/footer2.php"); ?>
“aolvideo”,
'http://feeds.bbci.co.uk/news/world/rss.xml“=>”bbcwn“,
'http://www.bing.com“=>”必应“,
'http://www.bravotv.com'=>'好极了',
'http://www.cartoonnetwork.com“=>”卡通网络“,
'http://feeds.cbsnews.com/CBSNewsMain?format=xml“=>”哥伦比亚广播公司新闻“,
'http://www.clicker.com/“=>”点击器“,
'http://feeds.feedburner.com/cnet/NnTv?tag=contentBody.1“=>”cnet“,
'http://www.comedycentral.com/“=>”喜剧中心“,
'http://www.crackle.com/“=>”噼啪声“,
'http://www.cwtv.com/feed/episodes/xml'=>“cw”,
'http://disney.go.com/disneyxd/“=>”迪士尼乐园“,
'http://www.engadget.com/rss.xml“=>”engadget“,
'http://syndication.eonline.com/syndication/feeds/rssfeeds/video/index.xml'=>'eonline',
'http://sports.espn.go.com/espn/rss/news“=>”espn“,
'http://facebook.com“=>”facebook“,
'http://flickr.com/espn/rss/news“=>”flickr“,
'http://www.fxnetworks.com//home/tonight_rss.php“=>”fxnetworks“,
'http://www.hgtv.com/“=>”hgtv“,
'http://www.history.com/this-day-in-history/rss“=>”历史“,
'http://rss.hulu.com/HuluRecentlyAddedVideos?format=xml“=>”葫芦“,
'http://rss.imdb.com/daily/born/'=>“imdb”,
'http://www.metacafe.com/“=>”元咖啡“,
'http://feeds.feedburner.com/Monkeyseecom-NewestVideos?format=xml“=>”monkeysee“,
'http://pheedo.msnbc.msn.com/id/18424824/device/rss/“=>”msnbc“,
'http://www.nationalgeographic.com/“=>《国家地理》”,
'http://dvd.netflix.com/NewReleasesRSS“=>”netflix“,
'http://feeds.nytimes.com/nyt/rss/HomePage“=>”纽约时报“,
'http://www.nick.com/“=>”五分硬币“,
'http://www.nickjr.com/“=>”尼克JR“,
'http://www.pandora.com/“=>”潘多拉“,
'http://www.pbskids.com/“=>”PBS“,
'http://www.photobucket.com/“=>”photobucket“,
'http://feeds.reuters.com/Reuters/worldNews“=>”路透社“,
'http://www.revision3.com/“=>”修订3“,
'http://www.tbs.com/“=>”待定“,
'http://www.theverge.com/rss/index.xml“=>“theverge”,
'http://www.tntdrama.com/'=>“tnt”,
'http://www.tvland.com/“=>”tvland“,
'http://www.vimeo.com/“=>”维梅奥“,
'http://www.vudu.com/'=>“vudu”,
'http://feeds.wired.com/wired/index?format=xml“=>”有线“,
'http://www.xfinitytv.com/“=>”xfinitytv“,
'http://www.youtube.com/topic/4qRk91tndwg/most-popular#feed“=>”youtube“,
);
$feed->set_feed_url(数组_键($url));
$feed->enable_cache(true);
$feed->set_cache_location('cache');
$feed->set_cache_duration(1800);//设置缓存时间
$feed->set_item_limit(1);
$success=$feed->init();//初始化simplepi
$feed->handle_content_type();//注意字符编码
?>
.png“/>
我在一些项目中使用SimplePie,这就是我为减少de页面加载时间所做的:我缓存结果
流量大约如下所示:
feed fetcher.PHP
index.HTML
中。实际上,在根文件夹中,我希望访问提要项内容以便于(或将来)阅读cron
作业,每20分钟左右获取一次提要.html
文件中。因此,我的页面加载速度非常快,因为我不需要等待抓取和处理我想检查的每个提要字符串
,或任何其他适合您需要的类型
这就是你要找的吗