Page 1 of 1

Parser: just wont work

Posted: Sun Oct 04, 2009 8:16 am
by kristallaju
OK maybe someone can take a look what im doing wrong

Code: Select all

<?php
 
//#### Parser
 
function rss_parser($feedurl,$notmore)
    
    {
    include "inc/config.php";
 
    //get the simplepie library
    require_once('simplepie.inc');
 
    $dahtmlheader ="Content-Type: text/html\r\nContent-Transfer-Encoding: 8bit\r\n";
 
    //grab the feed
    $feed = new SimplePie();
    //enable caching
    $feed->enable_cache(false);
    //init the process
    $feed->init();
     //let simplepie handle the content type (atom, RSS...)
    $feed->handle_content_type();
 
    $i=0;
 
    if ($feed->error)
        {
        echo $feed->error;
        };
        
        
        $feedurlcheck = preg_replace("/[^0-9a-zA-Z]/","",$feedurl);
        if (strlen($feedurl) > 50) {$feedurlcheck = substr($feedurlcheck, 0, 50);};
 
        foreach ($feed->get_items(0, 1) as $item)
        
           {
              if($notmore < $i +1){break;};
 
              $title = $item->get_title();
              $description = $item->get_content();
              $url = $item->get_link();
 
 
                if(file_exists("save/".$feedurlcheck.".txt"))
 
                    {
 
                    $lastpost = file_get_contents("save/".$feedurlcheck.".txt");
                    if($lastpost == $title){break;};
 
                    };
 
                      echo $output;
                      echo "<div class='topicheader'><h3>".$title."</h3></div>";
                      echo "<div class='topicbody'>".$url."<div class='clear'></div></div>";
 
 
                      if($i == 0)
 
                     {
 
                       $newlastpostitle = $title;
 
                     };
 
                $i++;
 
                     };
 
                      if($lastpost != $title)
 
                    {
 
                      $fh = fopen("save/".$feedurlcheck.".txt", "w");
                      fputs($fh, $newlastpostitle);
                      fclose($fh);
 
            };
 
    }
?>

Re: Parser: just wont work

Posted: Sun Oct 04, 2009 4:27 pm
by requinix
Are you going to describe the problem or do we have to guess?

Re: Parser: just wont work

Posted: Mon Oct 05, 2009 4:55 am
by cpetercarter
Your problem may lie here.

Code: Select all

foreach ($feed->get_items(0, 1) as $item)
In subsequent lines, you treat $item as an object ($item->getTitle() etc). But surely $item is either a string or an array. Perhaps you need $title = $item['title'];