tags:

views:

74

answers:

5

Hi all,

How do you print a new line break in CakePHP. I have tried this out:

echo "<b>\nhelloworld\n</b>";

instead of printing the it into three separate lines like this way:

<br>
helloworld
</b>

it just printed in this way when I viewed the HTML source code:

<b>helloworld</b>
+1  A: 

You could initially try just pressing enter and see if it's picked up...

If that doesn't work

Try doing it like this.

echo "<b>"."\n"."helloworld"."\n"."</b>";
Toggo
+1  A: 

that indeed is exactly how you add line breaks. What are you using to view the source code? Some tools, such as Firebug, normalise and reformat the source code for you which is why you might not be seeing the breaks.

nickf
+1  A: 

Try \r\n instead of \n.

Anax
This works. Thanks, Anax
+1  A: 

You have to escape the backslash:

echo "<b>\\nhelloworld\\n</b>";
JaKoPo
+1  A: 

Your original line of code worked fine for me. I see that Anax solved your problem, above, but I wonder why carriage returns should be necessary but only in some circumstances?

thesunneversets
difference between unix and windows. However, some windows editors understand will accept \n as a page break as well, or you have to tell them that it actually a unix format. no chance with notepad though. Also found this one `Most textual Internet protocols (including HTTP, SMTP, FTP, IRC and many others) mandate the use of ASCII CR+LF (0x0D 0x0A) on the protocol level, but recommend that tolerant applications recognize lone LF as well.' See http://en.wikipedia.org/wiki/Newline
Peter Schuetze