Ankündigung

Einklappen
Keine Ankündigung bisher.

RSS einbinden

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • RSS einbinden

    Moin,

    ich habe ein problem mit www.easyphp.org und zwar werden diese Fehlermeldungen bei mir angezeigt, wenn ich versuche einen RSS feed auf meiner Website anzuzeigen.


    über dem Header
    PHP-Code:
    <?php
    include 'include\rss.php';
    include_once(
    "include\analytics.php");

    $url 'http://rss.golem.de/rss.php?feed=RSS2.0';
    ?>
    oder irgen ein anderer RSS-Feed


    irgend wo im content
    PHP-Code:
       <?php
                            
                            $rss 
    = new RSSParser($url ,"utf-8");
                            
                            
    $s count($rss->titles);
                            if(
    $s 8)
                                
    $s 8;
                            for(
    $x 0;$x $s;$x++)
                            {
                                
                                
    $s1 explode("<a","".$rss->descriptions[$x]);
                                
    $s2 explode("></a>",$s1[1]);
                                
    $s2[0] = preg_replace("/maxImageHeight=400&maxImageWidth=400/","maxImageHeight=150&maxImageWidth=150",$s2[0]);
                                
    $image "<a".$s2[0]."id=\"rss_img\"></a>";
                                
    $text $s1[0].$s2[1];
                                
    $date $rss->pubDates[$x];
                                
    $t explode("/>",$rss->channel_image);
                                
    $logo "<a  href=\"http://www.irgend_eine_link.de\">".$t[0]."id=\"rss_logo\"/></a>";
                                
                                echo  
    "<p><span id=\"rss_date\">".$date."</span>";
                                echo  
    $logo."<br/>";
                                echo  
    "<a href=\"".$rss->links[$x]."\">".$rss->titles[$x]."</a>";
                                echo  
    "<hr id=\"rss_hr\"><br id=\"br\"></p><p>";
                                echo 
    $image."";
                                echo 
    $text."<br/></p><br/>";
                            }
                            
                            
    ?>
    Fehlermeldung:
    Notice: Undefined offset: 1 in E:\Program Files (x86)\EasyPHP-5.3.3\www\news.php on line 89

    Notice: Undefined offset: 1 in E:\Program Files (x86)\EasyPHP-5.3.3\www\news.php on line 92


    Die fehlerhaften Zeilen
    Zeile 89:
    $s2[0] = preg_replace("/maxImageHeight=400&maxImageWidth=400/","maxImageHeight=150&maxImageWidth=150",$s2[0]);
    Zeile: 92
    $date = $rss->pubDates[$x];

    die rss.php die mit Dreamweaver erstellt worden ist
    PHP-Code:
    <?php
    class RSSParser    {
        var 
    $channel_title="";
        var 
    $channel_website="";
        var 
    $channel_description="";
        var 
    $channel_pubDate="";
        var 
    $channel_lastUpdated="";
        var 
    $channel_copyright="";
        var 
    $title="";
        var 
    $link="";
        var 
    $description="";
        var 
    $pubDate="";
        var 
    $author="";
        var 
    $url="";
        var 
    $width="";
        var 
    $height="";
        var 
    $inside_tag=false;    
        function 
    RSSParser($file,$encType)    {
                
    $this->xml_parser xml_parser_create($encType);
                
    xml_set_object$this->xml_parser$this );
                
    xml_set_element_handler$this->xml_parser"startElement""endElement" );
                
    xml_set_character_data_handler$this->xml_parser"characterData" );
                
    $fp = @fopen("$file","r") or die( "$file could not be opened" );
                while (
    $data fread($fp4096)){xml_parse$this->xml_parser$datafeof($fp)) or die( "XML error");}
                
    fclose($fp);
                
    xml_parser_free$this->xml_parser );
            }
        
        function 
    startElement($parser,$tag,$attributes=''){
            
    $this->current_tag=$tag;
            if(
    $this->current_tag=="ITEM" || $this->current_tag=="IMAGE"){
                
    $this->inside_tag=true;
                
    $this->description="";
                
    $this->link="";
                
    $this->title="";
                
    $this->pubDate="";
            }
        }
        
        function 
    endElement($parser$tag){
            switch(
    $tag){
                case 
    "ITEM":
                    
    $this->titles[]=trim($this->title);
                    
    $this->links[]=trim($this->link);
                    
    $this->descriptions[]=trim($this->description);
                    
    $this->pubDates[]=trim($this->pubDate);
                    
    $this->authors[]=trim($this->author);
                    
    $this->author=""$this->inside_tag=false;
                    break;
                case 
    "IMAGE":
                    
    $this->channel_image="<img src=\"".trim($this->url)."\" width=\"".trim($this->width)."\" height=\"".trim($this->height)."\" alt=\"".trim($this->title)."\" border=\"0\" title=\"".trim($this->title)."\" />";
                    
    $this->title=""$this->inside_tag=false;
                default:
                    break;
            }
        }
        
        function 
    characterData($parser,$data){
            if(
    $this->inside_tag){
                switch(
    $this->current_tag){
                    case 
    "TITLE":
                        
    $this->title.=$data; break;
                    case 
    "DESCRIPTION":
                        
    $this->description.=$data; break;
                    case 
    "LINK":
                        
    $this->link.=$data; break;
                    case 
    "URL":
                        
    $this->url.=$data; break;                    
                    case 
    "WIDTH":
                        
    $this->width.=$data; break;
                    case 
    "HEIGHT":
                        
    $this->height.=$data; break;
                    case 
    "PUBDATE":
                        
    $this->pubDate.=$data; break;
                    case 
    "AUTHOR":
                        
    $this->author.=$data;    break;
                    default: break;                                    
                }
    //end switch
            
    }else{
                switch(
    $this->current_tag){
                    case 
    "DESCRIPTION":
                        
    $this->channel_description.=$data; break;
                    case 
    "TITLE":
                        
    $this->channel_title.=$data; break;
                    case 
    "LINK":
                        
    $this->channel_website.=$data; break;
                    case 
    "COPYRIGHT":
                        
    $this->channel_copyright.=$data; break;
                    case 
    "PUBDATE":
                        
    $this->channel_pubDate.=$data; break;                    
                    case 
    "LASTBUILDDATE":
                        
    $this->channel_lastUpdated.=$data; break;                
                    default:
                        break;
                }
            }
        }
    }
    ?>


  • #2
    Zitat von Saphier Beitrag anzeigen
    Zeile 89:
    $s2[0] = preg_replace("/maxImageHeight=400&maxImageWidth=400/","maxImageHeight=150&maxImageWidth=150",$s2[0]);
    Kann nicht sein, das würde eine andere Fehlermeldung ergeben. Der Fehler kommt aber wahrscheinlch dadurch zu Stande, dass du nicht prüfst, in wieviele Teile [man]explode[/man] die Zeichenkette zerlegt.
    Meinungen, die ich geäußert habe, sind nicht notwendigerweise meine eigenen. Abweichungen von der deutschen Rechtschreibung unterliegen dem Urheberrecht, dürfen aber unter den Bedingungen von verwendet werden

    Kommentar


    • #3
      Dafür brauchst du kein Script aus dem Netz. Schau dir mal simplexml an, damit solltest du ohne Probleme RSS Feed parsen können.

      Kommentar

      Lädt...
      X