hi there in a form I have a textarea where obviously text is entered. When the input is finished the content gets submitted to the server and is being stored in a database... When i display the input the user made within a table, the newlines are not visible. When I inspect the source the newlines are there, but within a table the newlines do not work... Is there any possibility of displaying the linebreaks within that table? I know, probably a really silly question but Im not to pro when it comes to things like html and css... Any help is really appreciated!
+1
A:
\n won't be rendered as a new line in HTML. You have to use a <br/>
to achieve this effect.
Use a string replace to replace all '\n' characters to '<br/>
'
If you are using a server side language like C# you can do this
private string PutLineBreaks(string strData)
{
string strReplaced = string.Empty;
Regex r = new Regex("/\n/g");
strReplaced = r.Replace(strData, "<br/>");
return strReplaced;
}
rahul
2009-09-24 09:20:01
actually, Id rather use a little JavaScript snippet to accomplish that task! anyway, thanks for the info!
Gnark
2009-09-24 09:29:42
A:
Use
<br />
, or rather <p></p>
if we talked about some text and new paragraph. (semantic better solution).
Rin
2009-09-24 09:23:34
I'm not sure replacing \n with a <p></p> would be semantically correct actually. <br /> is semantically a line break, as is \n. \n\n however would semantically be a paragraph.
Deniz Dogan
2009-09-24 09:28:31
You'd want to start the entire text block with a '<p>', and close the entire text block with a '</p>'. Then you can replace each '\n' with a '</p><p>', which will close one paragraph and start another.
Jarrett Meyer
2009-09-24 09:36:07