New line character not creating a new line

Using this code:

[code]

<?php echo "line1"; echo "n"; echo "line3"; ?> [/code]

gives me this HTML:

[code]

line1 line3 [/code]

which obviously doesn’t create a line break at all, so it just shows up on the page as “line1 line3”. I’ve had experience using PHP for all of ten minutes and am using PHP v. 5.1.4 running in safe mode. What’s wrong?

Line breaks such as n and rn (on Windows systems) break the line for text files, etc. If you want HTML to render a line break for you, you should use the
tag :wink:

Thank you for proving that I’m completely stupid. For some reason the official PHP manual makes it look like sticking n in an echo statement will automatically insert a line break (for instance the example output here: http://us.php.net/manual/en/language.types.array.php under Arrays Do’s and Don’ts). But then if n doesn’t insert a functional line break, is making the HTML more readable all that it’s good for?

What I think you mean, is that n is not doing what it’s supposed to do. But it does, I guarantee that. If you run PHP from the commandline, or have text with n characters written to a text file from the PHP script, it will work perfectly fine. The deviating factor in your issue is HTML: it doesn’t see the n at all, as it simply parses what’s relevant for it: HTML tags.
is more or less the HTML version of n.

You will see the difference that n makes when you view the HTML source code, rather than what’s being rendered by your browser.

Ah, but you’re assuming I’m competent enough to know that PHP is used for anything other than generating HTML. ;)

It’s always good to learn of new POVs :wink: Besides, it would be kind of rude to assume that you weren’t competent enough for such things.

Sponsor our Newsletter | Privacy Policy | Terms of Service