Pra*_*ani -4 php rss simplepie
我正在研究新闻应用程序,我需要解析当前的新闻RSS (Really Simple Syndication).
我找到了SimplePie库来RSS轻松解析feed.
首先,我直接在服务器上使用了这个库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;
?>
Run Code Online (Sandbox Code Playgroud)
但我在我的电脑上运行此文件,我得到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
我认为这是因为PHP版本,但我不认为我能做什么.
请帮忙...
提前致谢.
错误说:
不推荐使用:不再支持将参数传递给构造函数.请直接使用set_feed_url(),set_cache_location()和set_cache_location()
错误很清楚.你不应该这样做:
$feed = new SimplePie("https://news.google.com/news/feeds?pz=1&cf=all&ned=us&hl=en&topic=h&num=3&output=rss");
Run Code Online (Sandbox Code Playgroud)
(构造函数是在使用new运算符创建类实例时自动调用的函数,这是您的困惑.)文档明确说明:
以前,可以将提要URL和缓存选项直接传递到构造函数中.从1.3开始,这已被删除,因为它引起了很多混乱.
相反,你必须这样做:
$feed = new SimplePie();
Run Code Online (Sandbox Code Playgroud)
...并使用适当的方法提供参数.顾名思义,set_feed_url()可用于提供feed的URL.