Page 1 of 1

Double space from textarea

Posted: Fri Aug 21, 2009 3:40 pm
by sleepydad
I'm sure there's a simple solution to this. I have a PHP page with the following (edited for brevity) ...

Code: Select all

 
$bodyFromEmail=$_POST['message'];
$bodyFromEmail=stripslashes($bodyFromEmail);
$bodyFromEmail=str_replace("\r", "\n", $bodyFromEmail);
 
mail ($to, $subject, $bodyFromEmail, $headers);
 
The $bodyFromEmail is capture in PHP using

Code: Select all

 
echo "<textarea name='message' cols='50' rows='10' wrap='virtual'></textarea>";
 
When I send a test to myself, it comes across as double spaced in my email client. What can I do to fix this?

Thanks in advance -
sleepydad

Re: Double space from textarea

Posted: Fri Aug 21, 2009 3:50 pm
by requinix
Windows uses \r\n for newlines. If you replace each \r with a \n then you get \n\n.

Code: Select all

$bodyFromEmail=preg_replace('/\r\n?/', "\n", $bodyFromEmail);
That will replace Windows's \r\n and Mac's \r with a Unix \n.

Re: Double space from textarea

Posted: Fri Aug 21, 2009 4:06 pm
by sleepydad
That did it.

Muchas gracias.