views:

387

answers:

4

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
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
thanks
lovespring
+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
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
+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