Reputation: 227
Basically i'm trying to set something where a user enters some text into a textarea (and they press their enter key to add new lines) and then it takes the value from that text area and mails it out in the message of a new email to a specified contact.
All the mailing functionality works, but I need to be able to automatically add a new line when the user presses enter in the textarea.
Using this to get the info from the previous page/form and replace the \r\n:
$BREAKINGNEWS=$_POST['BREAKINGNEWS'];
$NEWS = str_replace("\r\n","<br />",$BREAKINGNEWS);
Then just adding $NEWS into the code to mail it out.
Doesn't seem to work though, just puts it on 1 line and doesn't replace the \r\n!
Any help is most appreciated :)
Upvotes: 4
Views: 2346
Reputation: 3563
Try to use nl2br. It will respect all different formats like \n, \r or \r\n (http://de.php.net/manual/en/function.nl2br.php)
Upvotes: 1
Reputation: 55758
There's the nl2br function built-in to PHP which does exactly what you want to achieve.
Upvotes: 1