Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

fixing what textareas do to input

by skazat (Hermit)
on Jun 05, 2000 at 05:23 UTC ( #16352=perlquestion: print w/replies, xml ) Need Help??
skazat has asked for the wisdom of the Perl Monks concerning the following question:

i'm having a bit of trouble trying to get input from text areas to format pretty much the same way as they are written out in the first place in the textarea on the webpage form. it seems sometimes extra lines are put into everyline break from them, etc, and this seems to be a platform problem... ie, macintoshes (like mine) might add a hard return followed by a newline while windows will add two newlines, i know there is one regex that can take care of it, (i've seen it here, honest) i was wondering if anyone's memory was a bit better than mine


Replies are listed 'Best First'.
Re: fixing what textareas do to input
by Zoogie (Curate) on Jun 05, 2000 at 08:42 UTC
    Perhaps: $data =~ s/(\r\n|\n\r|\r)/\n/g This converts CR's, LF's, and any combination of the two into a single newline (I hope... haven't tested it).
      If you output the textarea input in HTML you might consider changing the right hand side of Zoogies regexp to /<br>\n/g
      -- bash$ :(){ :|:&};:
      Would $data =~ s/(\r|\n){1,2})/\n/g work as well? (Unfortunately, I don't have time to test it out-- and I'm notorious for FUing my regexes the first time out.)

      The Autonomic Pilot

Re: fixing what textareas do to input
by httptech (Chaplain) on Jun 05, 2000 at 18:55 UTC
    In addition to using the s/\r\n/\n/g style expression to even out the linefeeds, you may want to set the textarea to WRAP="NONE" to force the user to do their own linefeeds. If you let the browser do the wrapping you may get inconsistent results.
      Except of course that that leads to annoyed users :)
        heh that's how the textareas work on Perl Monks (at least in my browser)... I don't find it annoying in the least. I rather like being able to choose where my lines break. I find it annoying when the browser wants to choose for me.
Re: fixing what textareas do to input
by skazat (Hermit) on Jun 05, 2000 at 23:56 UTC
    thats exactly the one i was looking for,
    kudos for everyone
    chocolate chip ones.

    -justin simoni

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://16352]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-10-20 15:53 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (119 votes). Check out past polls.