Friday, 28 December 2012

How to create RSS Feed XML in Core PHP?

Hi Guys,

I am back, after a long time but will continue further...

1. First of All create .htaccess file and write following line into it:
AddType application/x-httpd-php .xml


2. Now,  create an .xml file  and write following code (its an example):


<?php header('Content-type: text/xml'); ?>
<rss version="2.0" >
    <channel>
<title>Panjabilok | Panjabi Culture |  Composite Culture |  Life Style | Saddi Dharti te Log | Sabhyachaar | Faith and Religion | Tourism | Kids &amp; Youth | Science &amp; Technology | Media</title>
<description>Panjabilok | Panjabi Culture |  Composite Culture |  Life Style | Saddi Dharti te Log | Sabhyachaar | Faith and Religion | Tourism | Kids &amp; Youth | Science &amp; Technology | Media</description>
<link><?php echo $_SITE_PATH; ?></link>
<copyright>Copyright 2012. Panjabilok.net All Rights Reserved. Powered by Rubicon </copyright>
<lastBuildDate><?php echo strftime( "%a, %d %b %Y %T %z" , gmdate('Y-m-d H:i:s')); ?></lastBuildDate>


<?php
$query = "SELECT *, UNIX_TIMESTAMP(n_creation) AS pubDate FROM $_NEWS WHERE n_status = '1' ORDER BY n_id DESC LIMIT 10";
$newsResult = $db->query($query);
$data = '';
while($row = $db->fetchArray($newsResult)) { ?>
 
   <item>
        <title><?php echo $row['n_title']; ?></title>
        <description><?php echo $row['short_desc']; ?></description>
        <link><?php echo $_SITE_PATH.'page.php?pg=newsview&amp;n_id='.$row['n_id'].'&amp;c_id='.$row['category_id']; ?></link>
        <guid><?php echo $_SITE_PATH.'page.php?pg=newsview&amp;n_id='.$row['n_id'].'&amp;c_id='.$row['category_id']; ?></guid>
        <pubDate><?php echo strftime( "%a, %d %b %Y %T %z" , $row['pubDate']); ?></pubDate>
   </item>
<?php } $db->freeResult($newsResult); ?>

 </channel>
 </rss>


3. Its done!!!


Your RSS feed has been created.

Cheers!!!



1 comment:

  1. Hi,Thanks for sharing this Informative post. i really appreciate for this post.

    PHP Training in Ahmedabad

    https://www.excelptp.com/professional-training-programs/php-mysql-training.html

    ReplyDelete