John, et al -- ...and then John Holmes said... % % > If i have a textarea form input for users and they enter in return % spaces, % > how can i replace the ascci chars with html tags? % % It'd be great if they had a function for this...they could call it % nl2br() or something...
Yeah. It would be even cooler if that's what it did, eh? Maybe someone
should rename that nl2nl+br and write a *real* nl2br for those of us that
want to GET RID OF the newlines. I think that part of the reason this
question comes up often is because nl2br doesn't really do what its name
would lead us, or at least me, to think that it does.
Patrick, I just went through this a few weeks ago (Sep 06). I don't know
that the list has archives, or I'd send you there first (anyone with a
URL?), so all I can do is give you my result:
$fout = ereg_replace("(\n|\r)+","<br>",$fin) ;
This translates any newline and/or carriage return in your $fin string to
a <br> and puts the results in $fout. It will convert input like
this is
some input
to
this is<br>some input
and you no longer have a newline in the way. The only downside is that
this is
some input
ends up the same way because the regexp is greedy, but the upside is that
it will work for UNIX (\n), Mac (\r), and DOS/Win (\r\n) input.
HTH & HAND
:-D
--
David T-G * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
msg79522/pgp00000.pgp
Description: PGP signature

