SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: PHP Line break

  1. #1
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Line break

    Is there a way to do a line break in php date function?

    I have Day Month Year Time

    I want

    Day Month Year
    Time

    I've tried every possible way, I'm stumped.
    :-)

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Use two date functions? One to give you Day Month Year. One to give you Time.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're writing to file, or for command line display, then you add a \n to your output.
    If you're displaying in an html page, then you add a <br />
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    A xHTML break, or a line break?

    PHP Code:
    <?php
    echo date('d m Y <b\r />h:i:s');
    ?>
    PHP Code:
    <?php
    echo date("d m Y \r\nh:i:s");
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    A line break, or a xHTML break?

    PHP Code:
    <?php
    echo date('d m Y <b\r />h:i:s');
    ?>
    Cool! Didn't know you could do that

  6. #6
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha, I tried \r and \n but not together, will test this after my shower.

    Thanks guys.
    :-)

  7. #7
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dyfuCa View Post
    I've tried every possible way, I'm stumped.
    No, you have not.

    Code:
    date('D M Y').'<br>'.date('h:i:s A');

  8. #8
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why use 2 functions when I can combine it into one by asking a simple question?
    :-)

  9. #9
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dyfuCa View Post
    Why use 2 functions when I can combine it into one by asking a simple question?
    No reason, unless everything else failed.

  10. #10
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew there was a way to do it with just one date function, I just couldn't remember.

    I tried \r and \n but didn't think of adding them together, anyhow I used Silvers xHTML response

    Thanks.
    :-)


Bookmarks

Posting Permissions

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