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

时间:2015-05-15 13:01:53

标签: php simplepie

我正在使用SimplePie库进行Feed生成。我对所需的输出做了一些更改。它一直很好,直到今天。 这是我的代码:

<?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开发人员所以我的知识非常有限。我在这里阅读了很多答案,我试图实现它,但仍然存在问题。如果你发现这个问题很愚蠢而烦人,请原谅我。谢谢你的时间。

0 个答案:

没有答案