Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Preserve carriage return - line feed in html

Tags:

html

If have a field in my database with crlf's how do I preserve that in HTML??

Is there a standard way of doing this??

Malcolm

EDIT: I am actually doing an MVC app if that hepls.

like image 844
Malcolm Avatar asked Apr 19 '09 04:04

Malcolm


2 Answers

I think the best way to do that is to replace the \r\n sequence with <br /> tags, using whatever scripting language your database-backed website is in.

Other options include placing the text within a <textarea>. Or, if it is appropriate for your site, using akin to the <pre> tag (or the CSS attribute white-space: pre).

like image 64
poundifdef Avatar answered Sep 20 '22 00:09

poundifdef


You can search/replace those characters with <br /> to make the text output with breaklines. You could also use the <pre> tag to specify a particular piece of text's line breaks.

like image 22
Anthony Avatar answered Sep 19 '22 00:09

Anthony