Tutorial :How to print line break in cakePHP?



Question:

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>  


Solution:1

Try \r\n instead of \n.


Solution:2

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


Solution:3

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.


Solution:4

You have to escape the backslash:

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


Solution:5

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?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »