RSS Feed Not Working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpbob
Forum Newbie
Posts: 4
Joined: Sat Apr 10, 2010 9:46 pm

RSS Feed Not Working

Post by phpbob »

Hello everyone,

my first post here and I greet all pros and noobs ( I am one of the latter).

I wanted to include a rss feed so that articles and news about the topic of my webpage are
displayed (I dont want javascript although it works with it). I included the php code
for this in my site's code but it doesnt work! My hoster is supporting php as I have
some WP blogs running without any problems.

This is the code I should include:

Code: Select all

<?php $olderror_reporting =error_reporting(0);
include ("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Fnews.google.com%2Fnews%3Fned%3Dus%26topic%3Dm%26output%3Drss&newpage=1&chead=1&atl=1&desc=1&owncss=&eleminate=&auth=1&dts=1&width=300&max=5&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=1&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$HTTP_SERVER_VARS['SERVER_NAME'].$HTTP_SERVER_VARS['PHP_SELF']."&phpout=1");
error_reporting($olderror_reporting);
?>
can someone help me out wuth this problem?
Last edited by phpbob on Sun Apr 11, 2010 7:14 am, edited 1 time in total.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: RSS Feed Not Working

Post by cpetercarter »

You don't say what software/templating system you use for your web site. It is possible that it does not support embedded php.
phpbob
Forum Newbie
Posts: 4
Joined: Sat Apr 10, 2010 9:46 pm

Re: RSS Feed Not Working

Post by phpbob »

here is the code:


Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
<!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Solutions Description: A two-column, fixed-width design for 1024x768 screen resolutions. Version : 1.0 Released : 20091102 -->
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title></title>
 
 
  <meta name="keywords" content="" />
 
  <meta name="description" content=" " />
 
  <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
 
</head>
 
 
<body>
 
<div id="logo">

 
<p><em>
</em></p>
 
</div>
 
<hr /><!-- end #logo -->
<div id="header">
<div id="menu">
<ul>
 
 
</ul>
 
</div>
 
</div>
 
<!-- end #header --><!-- end #header-wrapper -->
<div id="page">
<div id="content">
<div class="post">




 
<br />
 
</div>
 
</div>
 
<!-- end #content -->
<div id="sidebar">
<ul>
 
  <li><br />
 
  </li>
 
  <li><br />
 
  </li>
 
  <li><br />
 
    <ul>
 
    </ul>
 
  </li>
 
</ul>
 
</div>
 
 
<?php $olderror_reporting =error_reporting(0);
include ("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Fnews.google.com%2Fnews%3Fned%3Dus%26topic%3Dm%26output%3Drss&newpage=1&chead=1&atl=1&desc=1&owncss=&eleminate=&auth=1&dts=1&width=300&max=5&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=1&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$HTTP_SERVER_VARS['SERVER_NAME'].$HTTP_SERVER_VARS['PHP_SELF']."&phpout=1");
error_reporting($olderror_reporting);
?>



 
<div style="clear: both;">&nbsp;</div>
 
</div>
 
<!-- end #page -->
<div id="footer">
<p>Copyright (c) 2010</p>
 
</div>
 
<!-- end #footer -->
<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
 
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-1701940-36");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>

cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: RSS Feed Not Working

Post by cpetercarter »

I guess that your template has a name like "index.html". Your server will not run php in a script with an "html" extension. Try renaming the file "index.php". But I am assuming that php is available on your site - your web host/server admin can tell you.
phpbob
Forum Newbie
Posts: 4
Joined: Sat Apr 10, 2010 9:46 pm

Re: RSS Feed Not Working

Post by phpbob »

well, I have renamed it to .php and my hoster is supporting php, otherwise I could not run my WP blogs.
But it still doesnt work, nothing is displayed, I really dont know why. I am sure as I am a php noob there is
something I am doing wrong, arent I?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: RSS Feed Not Working

Post by cpetercarter »

The php code which you are trying to run "includes" a file from a remote server. For security reasons, many web hosts configure php to prevent remote file inclusion. Talk to your web host about this. I think you would do better to go with the Javascript alternative.
phpbob
Forum Newbie
Posts: 4
Joined: Sat Apr 10, 2010 9:46 pm

Re: RSS Feed Not Working

Post by phpbob »

I have found this php code and it works, but I would like to display it in a normal way, not as a ticker. Moreover, I would like to add
a description and the link url. What exactly shall I change here?

Code:

Code: Select all

<div style="width:100%;" align="center">
    <?php
             $xmlFile = file("http://news.google.de/?output=rss"); // hier wird die XML-Datei als array eingelesen.
             $parser = xml_parser_create();
             xml_set_element_handler($parser, "startElement", "endElement"); // startElement verweist auf die gleichnamige funktion welche beim erreichen des Starttags aufgerufen wird.
                                                                        // endElement verweist auf die gleichnamige funktion welche beim erreichen des Endtags aufgerufen wird.
             xml_set_character_data_handler($parser, "cdata"); // cdata verweist auf die gelichnamige funktion welche für die verarbeitung dre daten zwischen den tags zuständig ist.

             $news = array(); // das array in den die news titel und deren link gespeichert wird
             $x = 0;          // dimension das $news arrays (für jedes news eine dimension) (item)
             $y = 0;          // dimension der news dinmension (für jede news-info eine weitere dinmension in der news dimension) (title und link)
                         // z.B. die erste news:  $news[0][0] = titel und $news[0][1] = link
               //      die zweite news: $news[1][0] = titel und $news[1][1] = link
               //      die dritte news: $news[2][0] = titel und $news[2][1] = link u.s.w
             foreach($xmlFile as $elem){        // jedes element, dass das $xmlFile-Array enthält...
                     xml_parse($parser, $elem); // wird an den XML-Parser ($parser) geschickt.
                     }
             function startElement($parser, $element_name, $element_attribute){
                      global $x;
                      global $y;
                      $element_name = strtolower($element_name);
                      if($element_name=="item"){ // wenn der start-tag "item" heißt...
                         $x++;                   // wird $x um eins erhöt.
                         }
                      if($element_name == "title"){       $y = 0; } // wenn der start-tag "title" heißt, wird $y auf "0" gesetzt.
                         elseif($element_name == "link"){ $y = 1; } // wenn der start-tag "link" heißt, wird $y auf "1" gesetzt.
                            else{ $y = 2; }                     // bei allem anderrem wird $y auf 2 gesetzt.
                      }
             function endElement($parser, $element_name){
                      // tut nix :)
                      }
             function cdata($parser, $element_inhalt){
                      global $x;
                      global $y;
                      global $news;
                      if(bin2hex(trim($element_inhalt)) != "" && $x >= 1){
                         $news[$x][$y] = $element_inhalt;  // hier wird der entsprechende inhalt zwischen den start- und end-tags in das news array gespeichert, entsprechend ihren bestimmten dinensionen. s. Beispiel weiter oben.
                         }
                      }
             xml_parser_free($parser);
             echo "<marquee>++";
        // hier erfolg die ausgabe des $news-arrays
             for($x=1;$x<count($news);$x++){
                 echo "++ <a href='".$news[$x][1]."'>".$news[$x][0]."</a> ++";
                 }
             echo "++</marquee>";
    ?> 
     
  </div>
Can maybe someone help?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: RSS Feed Not Working

Post by cpetercarter »

Try replacing this bit:

Code: Select all

 echo "<marquee>++";
        // hier erfolg die ausgabe des $news-arrays
             for($x=1;$x<count($news);$x++){
                 echo "++ <a href='".$news[$x][1]."'>".$news[$x][0]."</a> ++";
                 }
             echo "++</marquee>";
with this:

Code: Select all

echo "<ul>";
for ($x=1;$x<count($news);$x++) {
echo "<li><a href='".$news[$x][1]."'>".$news[$x][0]."</a></li>";
}
echo "</ul>";
Post Reply