Re: text areas and line brakes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux