?
Solved

RSS feed not showing item time

Posted on 2011-03-20
3
Medium Priority
?
33 Views
Last Modified: 2016-05-10
The time displays on RSS feed items is not correct, it is not  the time when the item was created and saved in database. Can you please tell me that how I can correct it. Please see the code bellow. You can see the result here: http://khatesabz.info/rss.php

<?php
echo '<?xml version="1.0" ?>';
echo '<rss version="2.0">';
echo '<channel>';
echo '<title>RSS Feed</title>';
echo '<link>http://--.info</link>';
echo '<language>fa</language>';
echo '<description>" &#1582;&#1591; &#1587;&#1576;&#1586; "</description>';

require_once 'kamen/serverdata.php';
$conn = mysql_connect("$dbHost","$dbUser","$dbPass");
mysql_query('SET NAMES utf8');
$db = mysql_select_db("$dbName");
mysql_query("SET CHARACTER_SET_RESULTS=NULL");
$sql = "SELECT * FROM lastnews ORDER BY id DESC LIMIT 15";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
echo '<item>';
echo '<pubDate>'.$row['date'].'</pubDate>';
echo '<pubTime>'.$row['time'].'</pubTime>';
echo '<title>'.$row['title'].'</title>';
echo '<link>'.$row['code'].'</link>';
echo '<description>'.$row['description'].'</description>';
echo '</item>';
}
echo '</channel>';
echo '</rss>';
?>
0
Comment
Question by:sam20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 35177261
RSS is a specialized subset of XML.  You can find more information on RSS here.  A quick search of that page will show you that there is no "pubTime" tag defined.
http://cyber.law.harvard.edu/rss/rss.html

The correct format for the RSS pubDate is RFC822 or RFC 2822.  In PHP this is date('r') format.  I think your problem arises from providing the wrong format for pubDate.  Check these links.
http://asg.web.cmu.edu/rfc/rfc822.html
http://php.net/manual/en/function.date.php

I would also like to suggest that the use of MySQL reserved words like "date" and "time" for column names is a recipe for confusion.  Here is an article that shows a little more about how to handle date and time in PHP and MySQL.  See if it helps you sort out the information that you have to store in the data base and reproduce in the XML of the RSS feed.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

An object-oriented version of the article is available here.
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html

HTH, ~Ray
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question