Question: the data is captured from a textarea to begin with.

Line1
Line2
Line3
etc

It is sent through this function before being stored in the DB (i'm open to better solutions, but if PDO is one of them, I don't understand it and have yet to get it to work)

```
function test_input($data) {
    global $conn;

    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    $data = mysqli_real_escape_string($conn, $data);

    return $data;
}

```

Which is my way of preventing injections (not my way but a way I found that has worked great until now its giving me this problem with line breaks and textareas)

I try to extract the data from the DB and display it in a textarea, and it shows \r\n instead of doing a line break. It is stored in the DB with the line breaks (i do not see the \r\n but instead i see the data on a new line)

I've tried nl2br, i've tried html\_entity\_decode, i've tried str\_replace \r\n to br (and then it just shows br literal instead of \r\n).

from the research I've found on this site, its the stuff i'm doing to it before i store it in the DB that is causing this but none of the solutions have worked for me.

help.

Answer: 
Replace the `\r\n` in the text with `&#13;&#10;` before putting it into to the textarea and showing it to the user.

It worked for me.
Html versus php and windows (carriage return and newline). Le
rning what happens
when you have a field of values in a buffer. A buffer can be coming from or going to an input/output device
What is inside the buffer may need to be substituted for a string appropriate to the device.
Pulling data from a DB line by line or from a SQL api query will require a regular expression and substitution operation repeating until all 
expressions are changed. Bullet proofing the input before it goes into the DB field is always a good idea.
I encountered a print problem that was caused by extra data (escape sequences) that caused the printers
to stop and wait for a reset sequence. No one understood why print jobs failed to print for something like
12 months. I wrote a filter and added it to the printers interface. PRoblem solved