Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textarea and carrige returns

Status
Not open for further replies.

jerehart

Programmer
Jun 10, 1999
61
US
Hey I am having problems with newlines entered into a textarea.

I have been trying to parse the textarea and replace the \r with <p>, but I am not getting it to work right. Everytime I view the output file I have ^M instead of a continued line or my paragraph tag. I am running on Solaris. any clues need more info?

or maybe a better way to store the file so I can read it out into table data area?

Miah
 
Or you can replace both \x0a and \x0d with <p>. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
okay I tried both bit I am still have the problems of having thr data show up as I like I keep getting ^M in my output files. here is my code
sub showtext {
# Split the text input into lines based
# upon new lines \n
@lines = split(/\n/,@_[0]);
foreach $line (@lines)
{
# Replace carriage returns on lines by
#themselves
# with <P> paragraph html tag
if ($line eq &quot;\n&quot;)
{
print INFO2 . &quot;<P>&quot; ;
}
}



and here is the output:

okay this is on continuous line in a textarea with wrap=vitrtual and show up in ^M
out of else the text box on multiple lines but
I hit return here^M
^M
and thwice here.
 
because you're doing this: @lines = split(/\n/,@_[0]);
you can't do this: if ($line eq &quot;\n&quot;)

you've split the text according to /n so now there is no \n in the text,so you can't do any conditions on \n.

what exactly are you trying to do?


:)
 
D'oh! Thanks for that I missed it. Well I am trying to make a script that will preserve the formating of a textarea into an output file. If I use the virtual wrap I get evrything on one line but if I enter


carrige returns that is where I am getting mucked up. That's why originally I was looking for \r. Does this give you more info?

Thanks for all of your help.
 
instead of using virtual wrap use hard.

ie.
Code:
<textarea name=text wrap=hard></textarea>

and then you could replace each occurrence of \n with <br> like this:
Code:
use CGI;
$query = new CGI;

$text_area = $query->param('text');
$text_area =~ s/\n/<br>/g;
hope this hepls

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top