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.
Try This May be help full

```
<?php 
function nl2br2($string) { 
$string = str_replace(array("\r\n", "\r", "\n"), "<br />", $string); 
return $string; 
} 
?> 

```