Newline charater has no effect

The newline character (\n) has no effect in any script I write. Why would that be?

Depends what you are trying to use it for.

Are you trying to see \n in HTML? Are you using a console? Are you wrapping it in PRE tags? Have you tried using PHP_EOL instead of \n?

Hi M@tt

I want the text to go to a new line. In the book I’m reading it uses \n to make text go to a new line but that does not work. But also the \t does not work either.

echo "This is a line \n This is a second line with a \t tab " will print This is a line This is a second line with a tab.

instead of
This is a line
This is a second line with a tab

But you didn’t really answer any of my questions. Where/how are you trying to use this new line character?

When I echo a line of text and I want part of it to appear on a new line

Are you viewing it in your browser? The newline character does not work with HTML. To see the newline character in HTML you must use PRE tags.

[php]
echo “

”;
echo “Line1\nLine2\nLine3\nLine4\nLine5\n”;
echo “
”;
[/php]

Thank you!

Sponsor our Newsletter | Privacy Policy | Terms of Service