Here is a simple code
<?php

echo "hello \n world";
?>

when I load the page(apache 1.3.27) on the internet explorer it shows:

hello world

but when I check the source it shows the correct output which is:

hello
world

anyone know why?

thank you

    to make it look like this:

    hello
    world

    then you must do like this:

    <?php

    echo "Hello<br>\nWorld";

    ?>

      thank you it works I forgot to use html tags
      but why does \n has no effect?

      because the following code also works the same:

      <?php
      echo "hello <br> world"
      ?>

        because the following code also works the same:

        That's not true. \n is a new line, equivalent to pushing enter in your browser. Look at the following code

        this 
                is 
        
        
        html                             
        
        
                              code

        You know what HTML processes that as in your browser?

        this is html code

        Why? There are no <br> tags. I can hit enter and space as many times as I want; spaces mean nothing in HTML. It helps you organize your code. Essentially, what \n does is the same as pushing enter.

        echo "<tr>\n<td width=200>\ncode\n</td>\n</tr>\n";

        will print in html as

        <tr>
        <td width=200>
        code
        </td>
        </tr>

        If you want a line break, which is completely different, in html you wouldn't write

        hello
        world

        to have it print that way. You would write

        hello<br>world

        Hope this clears up any confusion.

        Cgraz

          Thank you for your reply but I am not sure if you answered my originial question.

          Here is some php code I tried :
          <?php
          echo "hello \n world";

          echo "hello
          world";
          ?>

          The outout I got on internet explorer is: hello world
          Aren't they suppose to output

          hello
          world

          ???

            I figured it out now, but whats the function of \n in php anyways? Is it only used to organize the code?

              When you write to files, it's very useful. In HTML, you'll write "<BR />", but in file, HTML code is normally unuseful. So you put a "enter" by writing "\n".

                \n is also helpful when setting up a message for your email. In that case youw ouldn't use <br>, you'd use \n

                $msg = "Dear Bob,\n\n";
                $msg .= "I'm going to start a new line now.\n";
                $msg .= "Thanks for reading my email.\n\n";
                $msg .= "Cgraz";

                If mailed would output

                Dear Bob,

                I'm going to start a new line now.
                Thanks for reading my email.

                Cgraz

                  Write a Reply...