Reputation: 1514
I have a comment box and when somebody presses enter, Cake will put a \n (line feed) into the database. When I retrieve this from the db, it is displayed just like \n instead of an actual break or in HTML a
.
There seems to be no option for handling \n, which I cannot understand because it is common to push enter in a textarea. What am I doing wrong?
Thanks Chris
Upvotes: 0
Views: 2555
Reputation: 37
CakePHP has it's own method for that:
TextHelper::autoParagraph(string $text)
Check the documentation: https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html
Upvotes: 0
Reputation: 21743
you forget that there are php functions covering that :) nl2br() is what you are looking for
echo nl2br(h($data));
NOTE:
h() is for security reasons. always use h() first, than nl2br().
you dont need h() if you have html content. h() is only for plain text.
TIP: you can even enhance your bake templates to automatically display it correctly - see http://www.dereuromark.de/2010/06/22/cake-bake-custom-templates/ for details
Upvotes: 2