We help IT Professionals succeed at work.

Chopping Letters and Adding HTML tags and other characters!

sjaguar13
sjaguar13 asked
on
I need to get a bunch of report type things from people. I set up a form that will save the reports on my server. There will be three input boxes then on text area for the report. It will be saved in alphabetical order. Lets say input box 1 was Car, 2 was Chevy, and 3 was Corvette. The textarea was "It's a good car". I would need a file saved in C:\...server...\C\Car\Chevy\Corvette.txt. Corvette.txt would just be "It's a good car". The problems I run into though are, how do I get the first letter? ...server...\C\.. the directory C is because Car starts with a C. I could have it save as ${'input1'}\${'input2'}\${'input3'}.txt, but how do I get the first letter? I'm thinking I have to chop Car, but I don't really know how to do that. Also, Let's say Corvette was Grand Am instead. It would have to be saved as Grand_Am.txt, how to I replace a space with _? Finally, lets say the textarea was:
It's a good car.
I like it a lot.
I would need a <br> tag after the first sentence. How to I add that? If I get a whole bunch of text, what would I do?

Thanks!
Comment
Watch Question

CERTIFIED EXPERT

Commented:
which language is your cgi, perl?

Author

Commented:
Yeah, I'm using perl.
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
$input3 =~ tr/ /_/;
open FILE,">C:/...server.../".substr($input1,0,1)."/$input1/$input2/$input3.txt";
$textarea =~ s/[\cM\CJ]/<br>/g;
print FILE $textarea;

Author

Commented:
Ozo,
  Will you explain that? I'm guessing the 2nd line creates the file, substr gets the first letter? Somehow the third line puts the <br> on each line, and the last lines puts the textarea with the br tags in the file, I have no idea what the first line does.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
The first line changes Grand Am to Grand_Am
sjaquar13,

Try this:

use CGI qw(param);
$box1  = param("box1");
$box2  = param("box2");
$box3  = param("box3");
$textbox  = param("textbox");

$_ = $box3;
tr/ /_/;
$box3 = $_;

# I am not sure but I believe you have to have folders $box1 and $box2 defined on your server
# for the following to work.
$rptfilea = "c:\\xxxxxxxxxx\\$box1\\$box2\\$box3.txt";
 open(RPTOUTA,">$rptfilea");

# or  open(RPTOUTA,">>$rptfilea"); <-- if you want to append to the file instead of replace.

print RPTOUTA "$textbox";

close (RPTOUTA);

# at this point you would put in code that would print out the form again for the next report
# and would be good to display the report file that you just saved.

hope this helps,

      paintbrush
CERTIFIED EXPERT

Commented:
sjaguar13,

Did you get the solution you were looking for??

What solution, if any, did you use??

Pl. let us know.

NOTE: if you have found a solution on your own or if this question has become obsolete, please delete  it and free up your points.

Thanks,

Explore More ContentExplore courses, solutions, and other research materials related to this topic.