newline character \n ignored

Discussion in 'PHP' started by mancade, Nov 28, 2007.

  1. #1
    Hi,

    The newline character is being ignored. Anyone know why that is?

    Example code
    -------------

    <?php
    echo( "blah \n blah" );
    ?>

    Resulting output in web browser:
    --------------------------------

    blah blah

    Thanks in advance.

    Ade
     
    mancade, Nov 28, 2007 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #2
    hmm, i just noticed you dont need to enclose the string in ( ) when using echo

    you can use

    echo nl2br("blah \n blah");

    or

    echo 'blah <br /> blah';
     
    serialCoder, Nov 28, 2007 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    It did, but the browser doesn't interrupt system based strings like \n \r \t

    If you view the source of the page, you will definitely see that it did indeed create a new line.

    I use "\n" when I am running the script in Command Prompt/SSH, but if I am running the script on the web, I use <br/>.

    Either code of serialcoder will work.

    Peace,
     
    Barti1987, Nov 28, 2007 IP