hi all
please let me know how to fetch rss links through php i am getting some error how to fetch news links into website from rss feeds

error coming like this

Warning: Division by zero in D:\xampp\htdocs\rss_reader\index1.php on line 3

Warning: require_once(inc) [function.require-once]: failed to open stream: No such file or directory in D:\xampp\htdocs\rss_reader\index1.php on line 3

Fatal error: require_once() [function.require]: Failed opening required 'inc' (include_path='.;\xampp\php\pear\') in D:\xampp\htdocs\rss_reader\index1.php on line 3

<? 
header('Content-type: text/xml');
require_once(magi_press/rss_fetch.inc);
 ?>
<rss version="2.0">
<channel>
<id>Name of your site</id>
<category>A description of your site</category>
<link>http://localhost/sardana/</link>
<url>Your copyright information</url>
<?
$conn=mysql_connect("localhost","root","") or die("cannot connect");
$db=mysql_select_db("studyadda") or die("cannot select db");
$q="SELECT rss_feed_id,rss_feed_cat,rss_feed_title,rss_feed_url  AS newsurl
FROM news_rss_url LIMIT 0,15";
$doGet=mysql_query($q);

while($result = mysql_fetch_array($doGet)){

$url = $_GET['url'];
$rss = fetch_rss( $url );

echo "Channel Title: " . $rss->channel['title'] . "<p>";
echo "<ul>";
foreach ($rss->items as $item) {
	$href = $item['link'];
	$title = $item['title'];
	echo "<li><a href=$href>$title</a></li>";
}
echo "</ul>";
$rss = fetch_rss($result['rss_feed_url']);
?>
     <item>
        <id> <?=htmlentities(strip_tags($result['rss_feed_id'])); ?></id>
        <category> <?=htmlentities(strip_tags($result['rss_feed_cat'],'ENT_QUOTES'));?></category>
      <title><?=$result['rss_feed_title'];?></title>
        <url> <?php echo $result['rss_feed_url']; ?></url>
     </item>  
<? } ?> </channel> </rss>

//index1.php

using this magpierss library

please help me

    Remove the parentheses around your includes and requires, and do quote literal strings.

      johanafm wrote:

      Remove the parentheses around your includes and requires

      That's just a stylistic thing and will have no bearing on the code or how it executes.

      The division by 0 is coming because you're not quoting your strings as johanafm stated. Inside the require() call you need to quote the path and filename like you did with the header() call one line above it.

        hi bpat1434 and johanafm

        please tell me how to display rss feeds with php friends i have stored some feed urls to be displayed in front end as a news

          bpat1434;10927295 wrote:

          That's just a stylistic thing and will have no bearing on the code or how it executes.

          True, but I'd still advice against using those since they make it look like a function call but is parsed entirely differently

          foo($str) {
          	return 2;
          }
          
          // Works fine
          $foo = foo('file.php') . 1;
          
          // Warning: require(file.php1) failed to open stream: No such file or directory
          $req = require('file.php') . 1;
          
          // Same as above of course, but the error is more apparent (to me anyway)
          $req2 = require 'file.php' . 1;
          
          // While both these work of course
          $req2 = (require 'file.php') . 1;
          $req2 = (require('file.php')) . 1;
          

          And to get back to the original question. If your errors are gone, it ought to work. Your latest question is very general and it breaks down to: retrieve the feed, possibly do something with it and finally display the results.

          But perhaps you have a more specific question?

            they make it look like a function call but is parsed entirely differently

            I'll concede that point.

            @: If you're looking for us to do the work for you, then I suggest you follow the last link in my sig to the Internet.com Freelancer website and hire someone. Here at PHPBuilder, we're here to help push you in the right direction, or help you debug, not do the programming completely for you.

              hi bpat1434
              That is not my intention to get entire code from you. I am trying for rss feed links in the application for the past 7 days so i asked if you people can direct me in a right way to get a help using the url sent by you.

              thanks in advance friends

                There are plenty of tutorials on reading RSS feeds through PHP. The simplest would be to use Simplexml and just read the feed:

                <?php
                
                $xmlstr = file_get_contents('http://www.weather.com/rss/national/rss_nwf_rss.xml');
                $xml = simplexml_load_string($xmlstr);

                Now the XML is stored in an iterable object which you can loop over to get all the children.

                For example, to get the title of the feed above, I'd do:

                echo (string) $xml->channel->title;

                To get the <item> children (all the articles) I'd do:

                $items = array();
                foreach($xml->channel->children() as $child)
                {
                    if($child->getName() == 'item')
                    {
                        $items[] = $child;
                    }
                }

                Alternatively you could use an xpath query to get just those results:

                $results = $xml->xpath('channel/item');
                while(list( , $node) = each($result))
                {
                    echo (string) $node->title;
                }

                Hope that helps you out some.

                  hi bpat1434

                  Thank you very much

                  i got the solution

                  i am posting the code for users to refer it if there are anything to be changed please let me know.

                  <?php
                  
                  $xmlstr = file_get_contents('http://www.indiaedunews.net/rss/today.xml');
                  $xml = simplexml_load_string($xmlstr);
                  
                  echo (string) $xml->channel->title; 
                  
                  $items = array();
                  foreach($xml->channel->children() as $child)
                  {
                      if($child->getName() == 'item')
                      {
                          $items[] = $child;
                      }
                  }
                  
                  $results = $xml->xpath('channel/item');
                  /*print "<br>";
                  print ("<pre>");
                  print_r($results); 
                  print ("</pre>");*/
                  
                  //print count($results)."<br>";
                  
                  while(list( , $node) = each($results))
                  {
                      $newsstring= (string) $node->title;
                  
                  	echo "<a href=".(string)$node->link.">".$newsstring."</a>";
                  	echo "<br>";
                  
                  //	print($newsstring)."<br>";
                  	/*for($i=0; $i<count($results); $i++)
                  	{*/
                  	/*}*/
                  
                  } 
                  ?>
                  

                    hi bpat1434
                    i am getting output of newslinks and it is going to the parent url of the site how can we restrict it

                    thanks in advance

                      what do you mean it's going to the parent url of the site?

                        Write a Reply...