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 8 of 8

Thread: preg_replace

  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    preg_replace

    This has been driving me mad, how would i rearrange this date:
    Tue, 15 Nov 2011 23:53:13 +0000,

    To display in the format 15/11/11 23:53

    Thanks...

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    PHP Code:
    print date('d/m/y H:i',strtotime('Tue, 15 Nov 2011 23:53:13 +0000')); 
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    mossledossle (11-16-2011)

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the reply, i have this code:

    PHP Code:
    foreach($from as $tweet) {

    $data $tweet->created_at;

    $date = print date('d/m/y H:i',strtotime('$data'));

    echo 
    '<p>'.$date.'</p>';
        

    The date changes (obviously) but is in the previously mentioned format the output from this is just 31/12/69 17:00 1??
    Last edited by mossledossle; 11-16-2011 at 11:27 AM. Reason: Stupid misktake by myself $data is in ' '

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I need to use
    PHP Code:
    $tweet->created_at 
    As the variable for the time...

  • #5
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    Remove the single quotes in the call to strtotime and the print.

    PHP Code:
    $date date('d/m/y H:i',strtotime($data)); 
    You should actually be able to use the date object without the intervening variable.

    PHP Code:
    $date date('d/m/y H:i',strtotime($tweet->created_at)); 
    And to take it one step further and eliminate another variable.

    PHP Code:
    foreach($from as $tweet) {
         echo 
    '<p>' date('d/m/y H:i',strtotime($tweet->created_at)) . '</p>';

    Last edited by djm0219; 11-16-2011 at 11:30 AM.
    Dave .... HostMonster for all of your hosting needs

  • #6
    New Coder
    Join Date
    Nov 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks very much...

    I was only doing it that way to try to work out what was going on, it works now i had single speech marks around the variable in strtotime function.

    One other thing, at the end of the output there is a 1? where is this from?

    Quote Originally Posted by djm0219 View Post
    Remove the single quotes in the call to strtotime

    PHP Code:
    $date = print date('d/m/y H:i',strtotime($data)); 
    You should actually be able to use the date object without the intervening variable.

    PHP Code:
    $date = print date('d/m/y H:i',strtotime($tweet->created_at)); 

  • #7
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    You haven't removed the print in there. The one is the result of the print statement which you don't need. I used it in my original response simply so you could see what I posted would output.
    Dave .... HostMonster for all of your hosting needs

  • #8
    New Coder
    Join Date
    Nov 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djm0219 View Post
    You haven't removed the print in there. The one is the result of the print statement which you don't need. I used it in my original response simply so you could see what I posted would output.
    Thanks for your help, its much appreciated.


  •  

    Posting Permissions

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