-4

私はニュースアプリに取り組んでおり、から現在のニュースを解析する必要があり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; 
?>

しかし、私は自分の PC でこのファイルを実行しています。次のエラーが発生しました。

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のバージョンが原因で発生したと思いますが、どうすればよいかわかりません。

助けてください...

前もって感謝します。

4

1 に答える 1

6

エラーは言う:

非推奨: コンストラクターへのパラメーターの受け渡しはサポートされなくなりました。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");

コンストラクターは、オペレーターでクラスインスタンスを作成するときに自動的に呼び出される関数ですnew。それはあなたの混乱でした。)ドキュメントはそれを明示的に述べています:

以前は、フィード URL をキャッシュ オプションとともにコンストラクターに直接渡すことができました。これは多くの混乱を招いたため、1.3 で削除されました。

代わりに、これを行う必要があります。

$feed = new SimplePie();

...そして、適切なメソッドを使用してパラメーターを提供します。名前が示すように、set_feed_url()を使用してフィードの URL を提供できます。

于 2013-08-09T12:21:45.420 に答える