text file in window, each line end with \r\n, in unix, each line end with \n. Does textarea's post value follow this rule?
+2
A:
To make it simple: yes
Usually you just want to replace \n
by <br />
and that does the trick.
marcgg
2009-09-21 14:04:29
You only use that replace when placing the result of a post from a textarea in HTML output. However you are correct browser maintain the client platforms newline character sequence.
AnthonyWJones
2009-09-21 14:16:19
thanks
lovespring
2009-09-22 06:24:52
+2
A:
On Windows with Opera, Firefox and IE7 it ends the text lines with \r\n. I presume in Unix will be only \n, but don't have a system to test now.
rslite
2009-09-21 14:11:39
A:
When you press enter when typing in a textarea, it creates just a \n.
If you want to then display the data (formatted with line breaks) on a page, you need to to a str_replace on the text from your textarea to replace the \n's.
BraedenP
2009-09-21 14:11:44
+1
A:
a modified function I've used from php.net commetns to replace \n and \r into one
{or whatever you pass in}
function replaceNewLines($string,$replacement='<br />')
{
return preg_replace("/(\r\n)+|(\n|\r)+/", $replacement, $string);
}
$string = "this is \n\n\n a String with many \n\n\r\r returns!";
$string = replaceNewLines($string,'');
easement
2009-09-21 15:05:12