PHP to xml for RSS Feed

Discussion in 'PHP' started by mokimofiki, Nov 16, 2009.

  1. #1
    I posted this thread in xml and rss and got no replies so i'm trying here .... Please Help.

    I have created a php page that outputs an rss feed as it should look in an xml file. What I need to know now is how to make it readable as a feed?

    What I have now can be viewed at:
    http://www.mofikiworldwide.com/rssfeed2.php

    Any help would be appriciated and thank you all in advance.
     
    Last edited: Nov 16, 2009
    mokimofiki, Nov 16, 2009 IP
  2. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #2
    try this at the top of php page

    header ("content-type: text/xml");

    But it seems you are using htmlentities() or htmlspecialchars type of function otherwise why would < get converted to &lt;??
     
    shubhamjain, Nov 16, 2009 IP
    mokimofiki likes this.
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Ok I will post the code and the result so that everyone can see where the result is comming from.

    Code:
    <?php
    header("content-type: text/xml");
    
    echo "&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?&gt;<br />";
    echo "&lt;rss version=\"2.0\"&gt;<br /><br />";
    
    echo "&lt;channel&gt;<br />";
    echo "&lt;title&gt;Mofiki WorldWide RSS Feed&lt;/title&gt;<br />";
    echo "&lt;link&gt;http://www.mofikiworldwide.com&lt;/link&gt;<br />";
    echo "&lt;description&gt;Articles about Mofiki WorldWide, Website design, development, Search Engine Optimization, and Hosting. This Feed will also have tutorials about said categories.&lt;/description&gt;<br /><br />"; // What its about
    
    
    include('connect.php');
    $q = mysql_query("SELECT * FROM blog ORDER BY id DESC LIMIT 5") or die(mysql_error());
    while($r = mysql_fetch_assoc($q))
    {
    
    
    echo "&lt;item&gt;<br />";
    echo "&lt;title&gt;".$r['title']."&lt;/title&gt;<br />";
    echo "&lt;link&gt;http://www.mofikiworldwide.com/viewblog.php?blogid=".$r['id']."&lt;/link&gt;<br />";
    echo "&lt;description&gt;".$r['message']."&lt;/description&gt;<br />";
    echo "&lt;author&gt;Brandon Orndorff&lt;/author&gt;<br />";
    echo "&lt;pubDate&gt;".$r['date']."&lt;/pubDate&gt;<br />";
    echo "&lt;/item&gt;<br /><br />";
    }
    
    
    echo "&lt;/channel&gt;<br />";
    echo "&lt;/rss&gt;<br />";
    ?>
    Code (markup):

    And the result can be seen at:
    http://www.mofikiworldwide.com/rssfeed2.php


    It seems to display ok but it needs to actually be read as an xml file and I have no idea how to do this. I have faith this community will have te answer :) Thank you in advance.
     
    mokimofiki, Nov 17, 2009 IP
  4. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Ok it seems to work I just can't pull in the description as the entire article seemed to be my second issue. Thank you for your help
     
    mokimofiki, Nov 17, 2009 IP