Okay, you got me on that one, but why do you need to remove the
newlines? It should be stored in the database (if you're doing so) with
the  newlines and not the HTML breaks. You only use the nl2br() to
output it on a web page, so who cares if the new lines are still there?

The manual page explains this correctly, btw. It says that a "<br />"
will be inserted before all newlines.

---John Holmes...

> -----Original Message-----
> From: David T-G [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 23, 2002 7:10 AM
> To: PHP General list
> Cc: John Holmes; 'Patrick Lebon'
> Subject: Re: [PHP] Replace linefeed/newline from text inputs with <br>
> tag?
> 
> 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!



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

Reply via email to