我正在开发新闻应用程序,我需要从RSS (Really Simple Syndication)
.
我发现SimplePie库可以轻松解析RSS
提要。
首先,我在服务器上直接使用了这个库,我的php code
.
<?php
// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once('./php/autoloader.php');
// We'll process this feed with all of the default options.
$feed = new SimplePie("https://news.google.com/news/feeds?pz=1&cf=all&ned=us&hl=en&topic=h&num=3&output=rss");
// Set which feed to process.
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
foreach ($feed->get_items() as $item):
?>
<div class="item">
<h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
<p><?php echo $item->get_description(); ?></p>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php
endforeach;
?>
但是我在我的电脑上运行这个文件,我得到了以下错误:
Deprecated: Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly. in C:\xampp\htdocs\apps\liveibl\php\library\SimplePie.php on line 640
我认为这是因为 PHP 版本而发生的,但我不认为我能做什么。
请帮忙...
提前致谢。