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

Convert Line Break to <BR> (flatfile)

Status
Not open for further replies.

klibby

Programmer
May 30, 2001
51
US
There's probably a simple solution to this......

I'm writing a script that will leave a multilined textbox like the one im typing this into so users can leave a comment.... the script will write the contents of this box, with some other info into a flatfile database.... though I need all the information from one post to be on one line.. NOT go to the next line when the user goes to a new line in the text box....

So basically... what I need, is to convert all the line breaks the user made (whenever they hit enter)... to <BR> in the flatfile... or just something to keep everything on the same line.....

Any solutions?
 
thank you..... one question though... how would I use that?....

right now im using something like...

print DATABASE1 &quot;$input{'realname'}|$input{'csname'}|$input{'comments'}\n&quot;;

how would I use $Field =~ s/\r?\n/<BR>/g; in there?
 
I don't know if this'll work:

Code:
open(DATA,&quot;</loaction/file/fine.txt&quot;) or die (&quot;Unable to open file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 ($var1,$var2,$var3) = split(/\|/,$line);

$line =~ s/\r?\n/<BR>/g;
- PLEASE GO THERE! WE NEED MORE MEMBERS! :)
 
hmm.... thats to read the file right?.....
What I really need is so that when its writing the file it will convert line breaks to <BR>..... that way.. say the user types the following into a text box...

&quot;line 1
line 2&quot;...

and another user made the entry...
&quot;testing&quot;

normally, when printing to a flatfile this would look like....

&quot;username|time|line 1
line 2
username|time|testing&quot;

(this would confuse the script i have to read this file... it would think the line &quot;line 2&quot; is a completely seperate entry)

what I need this flatfile to look like after printing would be...

&quot;username|time|line 1<BR>line 2
username|time|testing&quot;

(so each entry has its own line)
 
Okay use this to parse your form...

Code:
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    local($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
    $value =~ s/<!--(.|\n)*-->//g;
    $in{$name} = $value;
}

Put that at the top of your script before your first sub.

Let's say your text area has the form name TextArea.

It will parse the form to $in{TextArea}.

In your file writing sub put $in{'TextArea'} =~ s/\r?\n/<BR>/g; at the top, and that will definetely work.

$in{TextArea} depends on what your text area name is. So if it's different, please change it.

I hope this works. :) - PLEASE GO THERE! WE NEED MORE MEMBERS! :)
 
lol

I reread your example so just add this at the top of your file writing sub:

$input{'TextArea'} =~ s/\r?\n/<BR>/g;

Remember &quot;TextArea&quot; is your text area form name. Change it to whatever it is. - PLEASE GO THERE! WE NEED MORE MEMBERS! :)
 
Schweet.... that helps a ton, thanks a million man =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top