--- David vd Geer Inhuur tbv IPlib <[EMAIL PROTECTED]> wrote: > $data = param('data'); > $data =~ s/\/n/<br>/g; > > Situation: I am reading into my script via > > param() a textarea called Job Duties. When I print > > out that parameter in perl all of the new lines are > > ignored and it prints as one long string.
Here's a slightly more sophisticated algorithm (he says with great Hubris(tm) ;-) that I wrote about a month ago. I have a function for either direction, and they translate double newlines into paragraphs as well as single ones into line breaks. (Probably appears identically in most browsers, but seems more "correct".) Also removes any doubt about \n handling, although it's possible that that doubt is justified only in my mind. Sorry about the word wraps, those were inserted by the Yahoo! email editor. - John sub NL2HTML { $_ = shift; s/\x0d\x0a/\x0d/g; # Strip LF out of CR/LF combinations (Convert DOS -> *nix) s/\x0d+$//g; # Strip out any CR at end, unnecessary (??? WHY NOT WORKING ???) s/\x0d{2}|\x0a{2}/<\/p><p>/g; # Replace double CR or LF with paragraph break </p><p> s/\x0d|\x0a/<br>/g; # Replace single CR or LF with line break <br> return "<p>$_</p>"; # Wrap whole thing in outside <p></p> } sub HTML2NL { $_ = shift; my $eol = shift || "\x0d\x0a"; # Default newline is CR/LF unless overridden s/^<p>(.*)<\/p>/$1/; # String out the outside <p>...</p> s/<\/p><p>/$eol$eol/g; # Replace internal paragraphs with double newlines s/<br>/$eol/g; # Replace internal line breaks with one newline return $_; } ===== "Now it's over, I'm dead, and I haven't done anything that I want; or, I'm still alive, and there's nothing I want to do." - They Might Be Giants, http://www.tmbg.com __________________________________________________ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]