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

format form input - keep paragraphs

Status
Not open for further replies.

mrthoule

Technical User
Joined
Aug 27, 2006
Messages
1
Location
US
I have a web form where I let users post text which I save in a mysql database. I have the following code to strip out the crap in the form. However, this code also strips out paragraph markers. Any idea how I can keep paragraphs, but avoid all the %2estuff+in+it%3E....

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
$i=0;
foreach $pair (@pairs) {
$i++;
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
chomp $value;
$FORM{$name} = $value;
}


Thanks
Todd
todd at mac os x dot com
 
If by paragraphs you mean keeping the \n characters in... you may just need to change one line:

Code:
 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

Code:
# put this up near the top of your script
use URI::Escape;

# replace that line with:
$value = uri_unescape ($value);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top