Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
P is for Practical
 
PerlMonks  

Problem displaying text with CGI

by Ovid (Cardinal)
on Jun 10, 2000 at 21:48 UTC ( [id://17545]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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."

Replies are listed 'Best First'.
Re: Problem displaying text with CGI
by Zoogie (Curate) on Jun 10, 2000 at 22: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 10, 2000 at 22: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 10, 2000 at 22: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 03: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 06: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 17: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
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://17545]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.