Reply to Re: html textarea --> php mail function produces additional line break

Your name:

Reply:


Posted by Pedro Graca on 01/12/06 14:17

Chris Schinzel wrote:
> I'm reading text from a html textarea field (standard wrap
> functionality, no value specified). If I display it via nl2br() (after
> html form submission), everything's ok. But if I send it via mail() the
> receiver gets each single line break (originating from textarea)
> displayed by TWO line breaks. So the text needlessly gets inflated...
> Can anybody help me out what to do to handle this problem?

Different clients will send line breaks differently:

un*x -- \n
mac -- \r
win -- \r\n
??? -- ???

So normalize input before anyhting else.

<?php
function normalize_linebreaks($text) {
$text = str_replace("\r\n", "\n", $text); /* win -> un*x */
$text = str_replace("\r", "\n", $text); /* mac -> un*x */
return $text;
}

mail($recipient, $subject, normalize_linebreaks($_POST['text_area']));
?>
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация