Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Problem displaying text with CGI

by Ovid (Cardinal)
on Jun 11, 2000 at 01:48 UTC ( #17545=perlquestion: print w/ replies, xml ) Need Help??
Ovid has asked for the wisdom of the Perl Monks concerning the following question:

Yet another humble begging of answers from wiser monks:

I have a form with textareas on it where I am setting the wrap to physical.

The form is submitted using a Perl CGI script which saves the data to a MYSQL database. Checking the database contents reveals that I am saving the data with carriage returns and line feeds. However, when I print the data back out to a Web page, the line feeds are stripped. Thus, the users cannot format their text into paragraphs.

Using PRE tags allows the line feeds to show up, but then the each line scrolls off the right edge of the screen. I've tried setting the table width to 100% and also tried setting it to 800 pixels, both to no avail. How do I get around this?

I am thinking that a perl substitution like this would work:

s/stuff to substitute/<P>\\n/g;
The problem is, I don't know what belongs in "stuff to substitute."

Comment on Problem displaying text with CGI
Download Code
Re: Problem displaying text with CGI
by Zoogie (Curate) on Jun 11, 2000 at 02:04 UTC
    $text =~ s/\n/<br>/g;
    perhaps? That might work better if the wrapping is set to "virtual"...

    - Zoogie

(jcwren) Re: Problem displaying text with CGI
by jcwren (Prior) on Jun 11, 2000 at 02:13 UTC
    $comment =~ s/(\r\n|\n\r)/<BR>/g; $comment =~ s/(\n|\r)/<BR>/g;
    will catch the fact that not all systems handle CR/LF pairs the same.

    --Chris
Re: Problem displaying text with CGI
by lhoward (Vicar) on Jun 11, 2000 at 02:22 UTC
    The HTML::FromText module does a great job of converting flat text to good HTML.
    use HTML::FromText; my $html=text2html($text,urls=>1,email=>1);
    Lots of options to do cool stuff (like make URL's and E-mails clickable, etc...) and you don't have to make the text display ugly on the browser by using PRE tags.
Re: Problem displaying text with CGI
by outcast (Monk) on Jun 11, 2000 at 07:18 UTC
    i would try some thing like this:
    <textarea row=25 cols=50> $comment =~ s/\n/<br>/g; $comment =~ s/\t/nbspnbspnbspnbsp/g;
Re: Problem displaying text with CGI
by Cybercosis (Monk) on Jun 11, 2000 at 10:55 UTC
    If you're definitely working with a CR/LF set, then $line =~ s/\xD\xA/<BR>/g; will replace it just fine.
    ~Cybercosis
Re: Problem displaying text with CGI
by Ovid (Cardinal) on Jun 11, 2000 at 21:32 UTC
    First, I have to say that I meant "newlines" rather than "linefeeds." I guess I was having flashbacks to my days working on mainframes (despite that comment, I'm in my early thirties). Next, I'll be looking for JCLmonks.

    After a bit of testing, s/\n/<BR>\n/g; seems to work fine. The users will actually start using this next week and I know something's going to go wrong, so I'll come back here and look at the other answers after they yell at me :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2014-08-20 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (121 votes), past polls