You are here: Re: [PHP] text areas and line brakes « PHP « IT news, forums, messages
Re: [PHP] text areas and line brakes

Posted by "Richard Lynch" on 10/14/05 11:19

On Tue, June 21, 2005 8:59 am, Sunny Boy said:
> if someone writes something in a text box, how would I convert a line
> break in the text area to echo a <br />? I think i'll have to get the \n
> and convert it. can anyone tell me?

While the two solutions provided so far are Really Nifty (tm) both ignore
the fact that Mac browsers/users may not be providing \n in the text area
in the first place.

<?php
//Convert line break to Unix standard:
$text = str_replace("\r\n", "\n", $text);
$text = str_replace("\r", "\n", $text);

//Convert to HTML:
$text = nl2br($text);
?>

I HIGHLY recommend you do the conversion to Unix as part of your input
filtering.

The nl2br should be done only on OUTPUT, imho.

YMMV

--
Like Music?
http://l-i-e.com/artists.htm

 

Navigation:

[Reply to this 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

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