By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

Newlines don't work.

P: n/a
Hi,

I am trying to output a newline, but this doesn't work:

echo "Line1\nLine2";

Before anyone says, I know HTML doesn't recognise newlines. I don't
need newlines in the rendered HTML, I need newlines in the SOURCE to
make it understandable.

Cheers,
Lister

Jan 31 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
echo("line1\n");
echo("line2");

or

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
echo($str);
?>

lister schreef:
Hi,

I am trying to output a newline, but this doesn't work:

echo "Line1\nLine2";

Before anyone says, I know HTML doesn't recognise newlines. I don't
need newlines in the rendered HTML, I need newlines in the SOURCE to
make it understandable.

Cheers,
Lister
Jan 31 '07 #2

P: n/a
..oO(lister)
>I am trying to output a newline, but this doesn't work:

echo "Line1\nLine2";
It does work. What PHP version do you use?

Micha
Jan 31 '07 #3

P: n/a
Rik
Vincent <ne*******@homeart.cjb.netwrote:
lister schreef:
>Hi,
I am trying to output a newline, but this doesn't work:
echo "Line1\nLine2";
Before anyone says, I know HTML doesn't recognise newlines. I don't
need newlines in the rendered HTML, I need newlines in the SOURCE to
make it understandable.
Cheers,
Lister
echo("line1\n");
echo("line2");

or

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
echo($str);
?>
While I'm a fan of heredoc, just using single quotes will also work.
--
Rik Wasmus
Jan 31 '07 #4

P: n/a
Michael Fesser wrote:
.oO(lister)
I am trying to output a newline, but this doesn't work:

echo "Line1\nLine2";

It does work. What PHP version do you use?

Micha
I find it weird too. The syntax is correct.

--

Feb 1 '07 #5

P: n/a
CH4:D schrieb:
Michael Fesser wrote:

>>.oO(lister)

>>>I am trying to output a newline, but this doesn't work:

echo "Line1\nLine2";

It does work. What PHP version do you use?

Micha


I find it weird too. The syntax is correct.
Yes, it should only cause a problem if it were enclosed in single
quotes. '\n' will just print \n, "\n" will print a linebreak. This can't
work:

echo 'Line1\nLine2';

(Just clarifying, since this distinction wasn't yet mentioned.)

--
CB
Feb 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.