Chrisissorry
Chrisissorry

Reputation: 1514

CakePHP sanitize line feed \n

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

Answers (3)

Hugo Tavares
Hugo Tavares

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

gerl
gerl

Reputation: 1181

You can also try echo str_replace("\\n", "<br />", $variable);

Upvotes: 0

mark
mark

Reputation: 21743

you forget that there are php functions covering that :) nl2br() is what you are looking for

echo nl2br(h($data));

NOTE:

Upvotes: 2

Related Questions