Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Editing Time Display

    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



    Code:
    <?
    $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;
    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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)

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have no clue how to do all this

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    mktime() I'm sure there'll be examples on there similar to what you want.

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I reviewed the link, but I can't understand how to apply it here.

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •