Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: catching newlines from textarea input

by Abigail-II (Bishop)
on Feb 28, 2003 at 11:52 UTC ( [id://239395]=note: print w/replies, xml ) Need Help??


in reply to catching newlines from textarea input

use strict; use warnings; sub ubb_txt { my $txt = shift; return "" unless ( defined $txt); my ($nl) = $txt =~ m{(\cM?\cJ)}; $txt =~ s{$nl$nl}{</p><p>}gs if (defined $nl); $txt =~ s{$nl}{<br>}gs if (defined $nl); $txt; } my $test = <<'--'; One fish Two fish Red fish Blue fish -- print ubb_txt ($test), "\n"; __END__ One fish<br>Two fish</p><p>Red fish<br>Blue fish<br>

Seems like the first regexp isn't eating all the newlines.

Abigail

Replies are listed 'Best First'.
Re: Re: catching newlines from textarea input
by maksl (Pilgrim) on Feb 28, 2003 at 11:59 UTC
    yes Abigail-II you are right on this sample, but with the input from the cgi textarea it does not :(
      And, care to show us what the input is from the textarea, or do you believe we are omniscient?

      Because, if the first regex does eat all the newlines, it's a bug in Perl.

      Abigail

        you are right abigail-II: in my little following test sript, using input from textearea, the regex definetly works correctly as above. don't know what damm happens in my cms, have to look deeper in it's lines.
        #!/usr/bin/perl -w use strict; use CGI; my $query = new CGI; my $text = cleanup_txt( $query->param( 'text' )); if ( $text eq "") { cast_form(); } else { print "Content-type:text/html\n\n"; print ubb_txt( $text); } sub cleanup_txt { my $str = $_[0]; return "" unless ( defined $str ); $str =~ s/[<>"'&|]//gs; return $str; } sub cast_form { print "Content-type:text/html\n\n"; print "<html><head><title>test textearea</title></head>"; print "<body>\n<form method=post action=\cgi-bin/"; print "/red/test.pl\"><textarea rows=\"5\" cols=\"55\" name="; print "\"text\"></textarea><br><input type=\"submit\""; print " value='Submit' name=submit\" value='Submit' name="; print "\"submit\"></form></body></html>"; } sub ubb_txt { my $txt = shift; return "" unless ( defined $txt); my ($nl) = $txt =~ m{(\cM?\cJ)}; $txt =~ s{$nl$nl}{</p><p>}gs if (defined $nl); $txt =~ s{$nl}{<br>}gs if (defined $nl); return $txt; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://239395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2025-06-15 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.