\n\r AWOL from textarea

Permalink
I cannot (but want to) preserve a newline from a text area. I have used nl2br. I have used str_replace for \r, \n, \r\n. As far as I can tell, the newlines make it into the database but not out of it.

In a textarea field I have input the following:

.....line
.....line
.....line

I save it in the database... (form method = post)

where it also looks like this.

.....line
.....line
.....line

Clearly the newlines have persisted into the database (which is fine with me).

I then pull the string out and apply the following code (hunting for newlines to deal with.)
echo str_replace("\n", '\n', $string);
echo str_replace("\r", '\r', $string);
echo str_replace("\r\n", '\r\n', $string);


...and I get the following

\n.....line.....line.....line\n
\n \r.....line.....line.....line\r
\r\n.....line.....line.....line\r\n

Instead of what I expected which was
\n.....line\n.....line\n.....line\n
\r.....line\r.....line\r.....line\r
etc..

How is it possible for the newlines to persist in the database after going in through $_POST but to be absent coming out? Is there a special character for newlines that I am missing? How do I preserve my newlines?

If at any point before I retrieve the string from the database, and paste it into notepad, it shows CRLF right where they ought to be, but once out of the database, I can only find them at the beginning and end of the string.

 
wclark07 replied on at Permalink Reply
PS if this might motivate anyone to reply, my current workaround is very very ugly

apply nl2br to string
use str_replace to convert <br /> to moomoomoocow
save in database
retrieve
use str_replace to convert moomoomoocow to </br>
echo

Please reply.
Stop the cows.