I am working on news app and i need to parse current news from RSS (Really Simple Syndication)
.
I have found SimplePie library to parse RSS
feed easily.
First of all i have used this library directly on server with my 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;
?>
But i am running this file on my PC, i got following error:
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
I think this was occur because of PHP version but i do not think what can i do.
Please Help...
Thanks in Advance.
The error says:
Deprecated: Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly
The error is quite clear. You are not supposed to do this:
$feed = new SimplePie("https://news.google.com/news/feeds?pz=1&cf=all&ned=us&hl=en&topic=h&num=3&output=rss");
(The constructor is the function that is called automatically when you create a class instance with the new
operator, it that was your confusion.) The documentation says it explicitly:
Previously, it was possible to pass in the feed URL along with cache options directly into the constructor. This has been removed as of 1.3 as it caused a lot of confusion.
Instead, you have to do this:
$feed = new SimplePie();
... and use the appropriate methods to provide the parameters. As the name suggests, set_feed_url() can be used to provide the feed's URL.