Forums

[resolved] New line break in PHP? (5 posts)

  1. onethousandseas
    Member
    Posted 2 years ago #

    Hi, I"m trying to format results on my search results page in a specific way. Right now it looks like this:

    <?php
    if($post->post_type == 'post') {
    echo the_time('Y');
    echo the_time('M');
    echo the_time('j');
    echo the_time('H:i');
    }
    else {print "Page";}
    ?>

    How can I format it with line breaks to look like this?

    <?php
    if($post->post_type == 'post') {
    echo the_time('Y'); [NEWLINE]
    echo the_time('M'); [NEWLINE]
    echo the_time('j'); [NEWLINE]
    echo the_time('H:i');
    }
    else {print "Page";}
    ?>
  2. dollars4click
    Member
    Posted 2 years ago #

    <?php
    if($post->post_type == 'post') {
    echo the_time('Y')."
    ";
    echo the_time('M')."
    ";
    echo the_time('j')."
    ";
    echo the_time('H:i')."
    ";
    }
    else {print "Page";}
    ?>

    http://www.coimbatoreindia.co.in

  3. Peter Boosten
    Member
    Posted 2 years ago #

    echo the_time('Y')."<br />"; could do the trick.

    Peter

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    echo
    the_time('Y').'<br />'.
    the_time('M').'<br />'.
    the_time('j').'<br />'.
    the_time('H:i');

    No need to echo, echo, echo, echo..

    Unless of course you're referring to \n aka new line..

  5. onethousandseas
    Member
    Posted 2 years ago #

    Thank you all!

    Here's the final code I used:

    <?php
    if($post->post_type == 'post') {
    echo the_time('Y')."<br />";
    echo the_time('M')."<br />";
    echo the_time('j')."<br />";
    echo the_time('H:i')."<br />";
    }
    else {print "Page";}
    ?>

    Marking it resolved!

Topic Closed

This topic has been closed to new replies.

About this Topic