user327712
user327712

Reputation: 3321

How to print line break in cakePHP?

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>

Upvotes: 0

Views: 4494

Answers (5)

thesunneversets
thesunneversets

Reputation: 2580

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?

Upvotes: 1

jakopo87
jakopo87

Reputation: 96

You have to escape the backslash:

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

Upvotes: 1

Anax
Anax

Reputation: 9372

Try \r\n instead of \n.

Upvotes: 3

nickf
nickf

Reputation: 546075

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.

Upvotes: 1

TDH
TDH

Reputation: 567

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>";

Upvotes: 1

Related Questions