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 isbrsome 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/pgp0.pgp Description: PGP signature
RE: [PHP] Replace linefeed/newline from text inputs with br tag?
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 isbrsome 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
Re: [PHP] Replace linefeed/newline from text inputs with br tag?
John, et al -- ...and then John Holmes said... % % Okay, you got me on that one, but why do you need to remove the In my case, I had a newline-delimited file of field@@data field@@data field@@data and when the data had an embedded newline like comment@@this is a long comment field@@data then it messed things up. Yeah, I learned about the possibility of using XML along the way, and I've already thought about serialize and base64 (which I *do* use inside the code, though not out in the file) for simple protections, but a requirement was that the text file also be readable and editable by people -- and, besides, I'm just extending this code rather than writing it :-) % 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? For output, it doesn't matter, as you say. My problem was input :-) % % The manual page explains this correctly, btw. It says that a br / % will be inserted before all newlines. Yeah, but that requires actual reading ;-) Who knows any more what TFM is? % % ---John Holmes... 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! msg79529/pgp0.pgp Description: PGP signature
RE: [PHP] Replace linefeed/newline from text inputs with br tag?
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... www.php.net/nl2br ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php