www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: rss feed

  1. #1
    Join Date
    May 2011
    Posts
    58

    rss feed

    hi, i can't make a rss feed. I don't know where the problem is. This is my code:
    PHP Code:
    <?php header('Content-type: text/xml'); ?>

    <?php 
    @include_once("./cfg.inc.php");

    $link mysql_connect($DBSERVER$DBUSER$DBPASS)
    or die(
    "Can't connect" );

    mysql_select_db($DB$link) or die ("Can't select DB");
    ?>

    <rss version="2.0">
    <channel>
    <title>Title</title>
    <description>Description</description>
    <link>Link</link>

    <?php
    $query
    mysql_query("SELECT `id`, `title`, UNIX_TIMESTAMP(`date`), `description`  FROM `rss` ORDER BY `date` DESC LIMIT 0,25");


    while(
    $result mysql_fetch_array($query)){
    ?>
         <item>
            <title> <?php htmlentities(strip_tags($result['title'])); ?></title>
            <description> <?php htmlentities(strip_tags($result['description'],'ENT_QUOTES'));?></description>
            <link>http://mysite.com/news/?id=<?php $result['id'];?></link>
            <pubDate> <?php strftime"%a, %d %b %Y %T %Z" $result['date']); ?></pubDate>
         </item>  
    <?php ?>  

    </channel>
    </rss>
    but when i open that .xml file in safari nothing appeared. I listened in google that i must turn on parser, something like this in .htaccess :
    PHP Code:
    AddType application/x-httpd-php .php .xml 
    but when i add this string to htaccess and then open my site, ordinary page and a my xml rss file, but they just was download, when i open they. I don't know how to make my php code work in that xml file. Please help me. Thanks.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,321
    Do you see anything in the browser if you do a "View source" on the resulting page?

    PS: Shouldn't your output start with an <?xml... tag?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2011
    Posts
    58
    Quote Originally Posted by NogDog View Post
    Do you see anything in the browser if you do a "View source" on the resulting page?
    yes i see a xml page without any php code, there is no any code that in <?php ?>
    Quote Originally Posted by NogDog View Post
    PS: Shouldn't your output start with an <?xml... tag?
    Seriously i don't know about it. I do it how it was in a lesson and it was like i show previously.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,321
    Quote Originally Posted by ijs View Post
    yes i see a xml page without any php code, there is no any code that in <?php ?>
    That's a good thing. It means the PHP was successfully processed on the server and output the XML text to your browser.

    Seriously i don't know about it. I do it how it was in a lesson and it was like i show previously.
    Try adding this:
    PHP Code:
    <?php header('Content-type: text/xml'); ?>

    <?php
    @include_once("./cfg.inc.php");

    $link mysql_connect($DBSERVER$DBUSER$DBPASS)
    or die(
    "Can't connect" );

    mysql_select_db($DB$link) or die ("Can't select DB");
    echo 
    "<?xml version='1.0' encoding='utf-8'?>";  // <<-------<<<<<<<
    ?>

    <rss version="2.0">
    <channel> 
    ...etc....
    (Echoing the xml tag within the PHP code can help avoid confusion by the PHP parser if you have PHP short tags enabled.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    May 2011
    Posts
    58
    Quote Originally Posted by NogDog View Post
    That's a good thing. It means the PHP was successfully processed on the server and output the XML text to your browser.
    I think that the php doesn't work at all in this file because i try to add something to xml output like $test = "test"; and then echo this in <description> tags but nothing was appeared
    i make like this but the ?> in this string: echo "<?xml version='1.0' encoding='utf-8'?>";
    is recognized like a php close tag, i think it's because xml file, i try to put in just in the start of file (because if not the error appeared, that told this string must be in start of file) but after that nothing change.
    may be i wrong and the rss feed had a xml markup but the .php file??
    i talk with my hosting support they told me that all checked up and all ok.

  6. #6
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by ijs View Post
    I think that the php doesn't work at all in this file because i try to add something to xml output like $test = "test"; and then echo this in <description> tags but nothing was appeared
    i make like this but the ?> in this string: echo "<?xml version='1.0' encoding='utf-8'?>";
    is recognized like a php close tag, i think it's because xml file, i try to put in just in the start of file (because if not the error appeared, that told this string must be in start of file) but after that nothing change.
    may be i wrong and the rss feed had a xml markup but the .php file??
    i talk with my hosting support they told me that all checked up and all ok.
    Can you more descriptive with "but nothing was appeared"? Are you viewing the source in a browser? Are you using an RSS reader?

  7. #7
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    When I last had a rss generator I used PHP to write the rss file;

    PHP Code:
    $fp fopen($xmlFile"w"); // make a new RSS file each time. 
        
    fwrite($fp$rss_header);  
        
    fwrite($fp,$rssContent);
        
    fwrite($fp$rss_footer);
        
    fclose($fp); 

  8. #8
    Join Date
    May 2011
    Posts
    58
    I'm using a Safari browser, it has a rss reader, so i use it. When i open xml file with that code that i mentioned previously, i see a rss feed but it contain only that was in a xml markup, nothing about php code, like it isn't in that file at all. How can i make that php code carried???

  9. #9
    Join Date
    May 2011
    Posts
    58
    Quote Originally Posted by Dasher View Post
    When I last had a rss generator I used PHP to write the rss file;
    I think about it, thanks for suggestion, but for now i really want to find a way through dynamic mysql connect

  10. #10
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by ijs View Post
    I'm using a Safari browser, it has a rss reader, so i use it. When i open xml file with that code that i mentioned previously, i see a rss feed but it contain only that was in a xml markup, nothing about php code, like it isn't in that file at all. How can i make that php code carried???
    It looks like you are missing all your "echo" statements:
    <title> <?php echo htmlentities(strip_tags($result['title'])); ?></title>
    <description> <?php echo htmlentities(strip_tags($result['description'],'ENT_QUOTES'));?></description>
    <link>http://mysite.com/news/?id=<?php echo $result['id'];?></link>
    <pubDate> <?php echo strftime( "&#37;a, %d %b %Y %T %Z" , $result['date']); ?></pubDate>

  11. #11
    Join Date
    May 2011
    Posts
    58
    I just tried what you suggest but it doesn't work, all my php code doesn't work. i try echo "hello world"; but it don't work too.

  12. #12
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    What environment are you doing this testing in? PHP and MySQL must be run from a server, such as apache or IIS.

    Generally speaking to create an rss feed you would create a file named rss.xml to do that you need to write the file out to the server. If you are just looking at what you think your browser will do with an rss feed, may not be correct if the rss feed is not really a rss feed. A php file must have a .php file extension, and an rss feed needs to be a .xml.

  13. #13
    Join Date
    May 2011
    Posts
    58
    i think i found a solution for my problem, i must use PHP to process XML files, i need do it somehow in the htaccess. Can someone tell some rules for this?

  14. #14
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by ijs View Post
    i think i found a solution for my problem, i must use PHP to process XML files, i need do it somehow in the htaccess. Can someone tell some rules for this?
    Usually I point to a PHP file directly rather than to get the engine to process all xml files. ie: rss.php instead of rss.xml.

  15. #15
    Join Date
    May 2011
    Posts
    58
    Quote Originally Posted by Dasher View Post
    What environment are you doing this testing in? PHP and MySQL must be run from a server, such as apache or IIS.

    Generally speaking to create an rss feed you would create a file named rss.xml to do that you need to write the file out to the server. If you are just looking at what you think your browser will do with an rss feed, may not be correct if the rss feed is not really a rss feed. A php file must have a .php file extension, and an rss feed needs to be a .xml.
    English is not my native language, and if i clear understood what you told, i'm doing right. OK how i did my rss file: I made a file rss.xml, then i paste this
    PHP Code:
    <?xml version='1.0' encoding='utf-8'?>
    <?php header
    ('Content-type: text/xml'); ?>
    next i add a top of rss feed xml markup
    next one i connect to mysql and take from base info to fill items.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles