...

View Full Version : Editing Time Display



ssskaya
04-03-2007, 09:07 PM
I am using the below script as an RSS parser.

It turns out RSS feeds in the following format: Date - Title


e.g.
11 Apr - Ralph Nader Wins!

How should I edit the script in order to get this instead:


Ralph Nader Wins!
2 days ago




<?
$strip_tags = true;
//set this to true if you are going to constrain the length of the string or if you want to get rid of all html except for links

$allowed_tags = '';//<a>
$constrain_string = true;
$day_limit = 4;
//set this to true if you want the string to be a creatin amount of characters long. $strip_tags must be set to true for this to work.

$string_limit = 400;
$feeds = array();

$feeds[] = array('feed'=>'http://www.sitename.com/index.xml','type'=>'rss','name'=>'Site Name',
'href'=>'http://www.sitename.com');

$rss_parser = new dailyTopTen();

$top_ten = array();
$top_ten = $rss_parser->getfeeds($feeds);

$xhtml = '';
$counter = 0;
foreach($top_ten as $_date => $feeds)
{
$counter++;
if($counter<=$day_limit )
{
foreach($feeds as $feed)
{

$xhtml .= '<strong><font color="#555555">'.date('d M',strtotime($_date)).'</font></strong> - '.'<a href="'.$feed['LINK'].'">';
$xhtml .= $feed['TITLE'];
$xhtml .= '</a> <img alt="'.$feed['NAME'].'" src="'.$feed['NAME'].'.gif" /><br />';
}
}
}
echo $xhtml;
?>

Fumigator
04-03-2007, 09:19 PM
Step one: Convert the date/time into a unix timestamp using mktime().

Step two: Convert the date/time of RIGHT NOW into a unix timestamp using mktime().

Step three: Find the duration in seconds between the two timestamps. (Hint: duration = NOW timestamp minus news-timestamp)

Step four: Convert the number of seconds into number of days. (Hint: seconds divided by 3600 is days)

ssskaya
04-04-2007, 12:33 AM
I have no clue how to do all this :)

Nightfire
04-04-2007, 12:43 AM
mktime() (http://php.net/mktime) I'm sure there'll be examples on there similar to what you want.

ssskaya
04-04-2007, 05:51 PM
I reviewed the link, but I can't understand how to apply it here.

Fumigator
04-04-2007, 06:24 PM
I take it you are not a programmer and have no programming training or experience. I would suggest you take some programming classes to learn how to convert a set of instructions into code.

iLLin
04-04-2007, 06:35 PM
Look at your code, you dont need all that, just change your format

date('d M',strtotime($_date)

See that, look up the date function and apply the format you want.

EDIT: Nvm you do need to use mktime as you want it to show "2 days ago". Sorry Fumigator, jumped the gun on that.

LISTEN TO Fumigator! :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum