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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter

Status
Not open for further replies.

hunter13605

Technical User
Apr 7, 2006
44
0
0
US
Back to it again. You have all been helpful in the past so i'm hoping that you can help me once more...

In the past i had a problem with commas and was given code how to fix it so it would replace the comma with the code for a comma...

Code:
$dob =~ s/,/,/g;
$best =~ s/,/,/g;
$worst =~ s/,/,/g;
$csao =~ s/,/,/g;
$future =~ s/,/,/g;
$will =~ s/,/,/g;

now i have a need to do something similar when they press the enter key within a text box... right now, when the enter key is pressed while in a text box, it will start a new line, or so it appears. After clicking save it reads the enter as being the end of the save line and creates a blank user which really screws things up...

So, sorry this is so long, but if anybody has any ideas i would greatly appreciate them. thank

Brian
 
Code:
$textarea=~s/\r\<br>/g;

HTH
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
That's for a carriage return, try \n (newline) as well, or
Code:
$textarea=~s/\r\n/<br>/g;
The <br> is just a html break, you can use something else if needs be

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
You are so AMAZING... you just made my day... i've been trying to figure this out all day. I knew that i needed to replace the line break with <br>, but for the life of me, i couldn't think of how to do it.

Thanks a lot
Brian
 
ok, one more quick question... if i want to save the data containing the fixed line brakes to a text file it is going to save the line breaks with <br> instead of showing the line breaks.

What i am wondering is if i can also use that code to find the <br> and replace it with /n... would that work if it was done right before it was saved to a text file?

the text file is something that is going to be printed and should look exactly as it was typed.

thanks again, you've been a great help
 
if the text file is going to be printed then don't change the line breaks (\r\n) to <br> in the first place.

- Kevin, perl coder unexceptional!
 
Just a little tip after looking at your original post to save you some typing. You can do the same replacement in a number of variables like so:
Code:
s/,/&#44;/g; for ( $dob, $best, $worst, $csao, $future, $will, );
 
Given your multiple requirements for print and display, you could consider holding the 'lines' from your text box in an array, stripped of any kind of separators. Then you have clean data, held independently of its output form. This makes it easy to format the output however you like:
Code:
# html output

print join("<BR>", @array);

# printed form

print join("\n", @array);

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Kevin,

I need to change the line breaks because the information is stored with the information from 210 other students in a mass, unformated text file, and must be editable by each user until the deadline... then from the admin account there will be a button to generate the printable text file...

I was thinking that when it comes time to make the printable file that i could change the <br> back to a /n which would then be saved to the printable version...

thanks for your help
Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top