let us say, we have a table database with the url,publish date and title of an article. So can I use php inside xml files without using CDATA so that I generate the xml code from php? For example: <?php $query = "SELECT * bla bla bla"; $results = mysql_query($query); while ($row = mysql_fetch_array($results)) { echo "<item><br> <title>{$row['title']}</title><br> <link>{$row['link']}</link<br> <guid>{$row['link']}</guid><br> <pubDate>{$row['date']}</pubDate><br> <description>{$row['subject']}</description><br> </item><br>"; } ?> PHP: Could this work?
Hey Scutari Not sure about your echo line with the {}, but that may just be my limited knowledge on php. In short, you sure can create a dynamically updated rss feed using php. Below is an example (bu if your echo method works, your way will work I think): <?php echo"<?xml version='1.0' encoding='UTF-8'?>"; ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>Your title</title> <description>Your description</description> <link>www.yourlink.com/</link> <lastBuildDate><?php echo date(r);?></lastBuildDate> <pubDate>Fri, 22 Aug 2008 22:47:37 +0200 [just needs to be in this format - change the values to your liking]</pubDate> <?php $sql=mysql_query("SELECT * blah blah blah"); while($row = mysql_fetch_array($sql)) { ?> <item> <title><?php echo$row['title']; ?></title> <description><?php $row['description']; ?></description> <link>your link here</link> <pubDate><?php //This next php code is just because my DB doesn't store the dates in the correct format. $my_date=$row['datetime']; $my_time=strtotime($my_date);echo date("r", $my_time); ?></pubDate> </item> <?php } ?> </channel> </rss> Code (markup): Change the mysql_querystring and the $row[]s to your configuration and you should be good to go. Naturally you'll also need to connect to your database ***Naturally you'll need to call your file name.php instead of name.xml
Hey I have tried to do what you said..but I think that the rss reader will not read the php extension..
That should not pose a problem. The important thing is that the first thing you declare is that this is <?xml version='1.0' encoding='UTF-8'?> Code (markup): and then that it is <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> Code (markup): That will let the rss reader know what kind of document we're talking about.