I want to make a rss feed and i know how to make it with an xml page but i want it to automatically use data from a database and i need the page to be a .php for that. anyway i can make a working feed with a php page?
XML/PHP rss feed?
haha, good timing, i just figured this one out the other day
ok here's the scam, basically we're going to force your server to process your xml file as a php file.
Couple steps here.
1) create a directory on your server for your rss feeds
2) create an .htaccess file for that directory, the only tag you'll need is:
AddType application/x-httpd-php .xml
3) create your xml file, on the first line you must have the following:
%26lt;? header('Content-type: text/xml'); ?%26gt;
4) go ahead and create your rss feed, but now you can use php freely through out the file, and when the file is accessed it will be treated as an xml file while being executed as a php file
Heres an example of a feed using the crap i just talked about - make sure you remember to strip all html out of your data, else the feed will explode. Also, be sure to save the file as .xml, and not .php
rockon brotha
%26lt;? header('Content-type: text/xml'); ?%26gt;
%26lt;rss version="2.0"%26gt;
%26lt;channel%26gt;
%26lt;title%26gt;title title blahblah%26lt;/title%26gt;
%26lt;description%26gt;i'm a description, go team%26lt;/description%26gt;
%26lt;link%26gt;%26lt;/link%26gt;http://www.woooooooobaby.com/%26lt;/link%26gt;
%26lt;copyright%26gt;2007%26lt;/copyright%26gt;
%26lt;?
include("../db_connect.php");
$dool=mysql_query("SELECT * FROM events WHERE active='1' AND date %26gt;= CURDATE() ORDER BY date ASC");
$num_resultsol=mysql_num_rows($dool);
for($xa=1; $xa%26lt;=$num_resultsol; $xa++){
$rowol=mysql_fetch_array($dool);
$dateol=explode('-', $rowol['date']);
$link='http://www.rockon.com';
$title=$dateol[1].'/'.$dateol[2].'/'.s... 2, 3).' - '.stripslashes($rowol['name']);
$body=stripslashes($rowol['Event']);
$gid=$rowol['EventId'];
?%26gt;
%26lt;item%26gt;
%26lt;title%26gt; %26lt;?=htmlentities(strip_tags($title, 'ENT_QUOTES')); ?%26gt;%26lt;/title%26gt;
%26lt;link%26gt;%26lt;?=$link;?%26gt;%26lt;/link%26gt;
%26lt;description%26gt; %26lt;?=htmlentities(strip_tags($body,'ENT_QU...
%26lt;/item%26gt;
%26lt;? } ?%26gt;
%26lt;/channel%26gt;
%26lt;/rss%26gt;
No comments:
Post a Comment