调整 Simplepie 时数组到字符串的转换错误

Array to String Conversion Error while tweaking Simplepie

我正在使用 SimplePie 库生成提要。我为所需的输出做了一些更改。直到今天它工作得很好。 这是我的代码:

<?php
header('Content-type: text/plain; charset=utf-8'); 
// Include the SimplePie library
// For 1.0-1.2:
#require_once('simplepie.inc');
// For 1.3+:
require_once('autoloader.php');

// Create a new SimplePie object
$feed = new SimplePie();

// Instead of only passing in one feed url, we'll pass in an array of three
$feed->set_feed_url(array(

'http://localhost/full-text-rss/makefulltextfeed.php?url=dynamic.feedsportal.com%2Fpf%2F555218%2Fhttp%3A%2F%2Ftoi.timesofindia.indiatimes.com%2Frssfeedstopstories.cms&key=1&hash=759dbac5d2121d4b7bc31ee9119d65a44a73fb6d&max=10&links=preserve&exc=1&format=json'

));
//Caching is enabled
$feed->enable_cache(true);

//timeout
$feed->set_timeout(40);

// We'll use favicon caching here (Optional)
//$feed->set_favicon_handler('handler_image.php');

// Initialize the feed object
$feed->init();

// This will work if all of the feeds accept the same settings.
$feed->handle_content_type();



 if ($feed->error)
 { 
 echo $feed->error; 
 }

 $newspaperName = array('Google News');  

 $i = 0;
 $j = 0;
 $response = array(); 
 $response["NewsItems"] = array(); 
 foreach ($feed->get_items() as $item)
 {


        $feed = $item->get_feed();

        //$permalink =
        //$NewsItems["Count"] = html_entity_decode($feed,ENT_QUOTES, "UTF-8");//html_entity_decode($item->get_id(),ENT_QUOTES, "UTF-8");



        $NewsItems["ArticleLink"] = html_entity_decode($item->get_permalink(),ENT_QUOTES, "UTF-8");//$permalink;

        $NewsItems["Title"] = html_entity_decode($item->get_title(), ENT_XHTML, "UTF-8"); 

        $NewsItems["Content"]= html_entity_decode($item->get_content(), ENT_XHTML, "UTF-8"); 
        if($i==10)
        {

         $i = 0;
         $NewsItems["Source"] = html_entity_decode($newspaperName[$j+1],ENT_QUOTES, "UTF-8");
         $j++;
        }
        else
        {

         $NewsItems["Source"] = html_entity_decode($newspaperName[$j],ENT_QUOTES, "UTF-8");;
         $i++;
        }

        $feed = $item->get_feed(); 

        $NewsItems["SourceLink"]= html_entity_decode($feed->get_permalink(), ENT_XHTML, "UTF-8");

        $feed = $item->get_feed(); 

        $NewsItems["SourceTitle"] =       html_entity_decode($feed->get_title(), ENT_XHTML, "UTF-8");

        $NewsItems["Date"]= html_entity_decode($item->get_date('j M Y |   g:i a T'), ENT_XHTML, "UTF-8");

        array_push($response["NewsItems"], $NewsItems); 
}
echo json_encode($response);
?>

但是今天突然出现错误:

Notice: Array to string conversion in C:\xampp\htdocs\simplepie\IndiaEnglishTopStories.php on line 38
Array{"NewsItems":[]} 

第 38 行是:

echo $feed->error;

我不是 php 开发人员,所以我的知识非常有限。我在这里读了很多答案,我试图实现它,但问题仍然存在。如果您觉得这个问题愚蠢且烦人,请原谅我。谢谢你的时间。

你试图回显数组这是不可能的。 $feed->error 是一个数组。

改为

foreach($feed->error as $err)
  echo $err;

var_dump($feed->error)

print_r($feed->error)

How to echo or print an array in PHP?