There seems to be a lot of confusion surrounding line breaks. You’re probably familiar with this:
\r\n
This is a line break, right? Well it can be. It depends on if it’s processed as normal text or not.
Let’s say a user is submitting a form and in the textarea, they add some line breaks. Let’s say they miss a field and you have the form printing out it’s own POST values (so they don’t accidentally lose anything), like this:
<textarea cols="32" rows="6" name="description"><?=$_POST['description'];?></textarea>
This is pretty simple, it’s just printing out the value of the posted description variable. But like I said a minute ago, if they had put line breaks in their textarea, their information will be posted in the textarea again, but it will look like this:
Information on Line 1\r\nInformation on Line 2
The problem here is that the \r\n is getting changed to normal text. To change it back, we replace it with itself, but with double quotes, returning it back to code as opposed to normal text. Here’s the final result:
<textarea name="description" rows="6" cols="32"><?=str_replace('\r\n',"\r\n",$_POST['description']);?></textarea>