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 开发者_JAVA百科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>
Try \r\n
instead of \n
.
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>";
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.
You have to escape the backslash:
echo "<b>\\nhelloworld\\n</b>";
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?
精彩评论