Forum Moderators: coopster & phranque

Message Too Old, No Replies

Encoding Special Characters

Encoding Special Characters

         

energylevel

9:42 am on May 11, 2004 (gmt 0)

10+ Year Member



Anyone help a novice .. I want to know how to convert special characters like " for example from form input

Thanks ............

VectorJ

2:30 pm on May 11, 2004 (gmt 0)

10+ Year Member



Special characters are converted by the browser into their hexadecimal ascii values (with a % in front of them). You can either use CGI.pm to parse the query string for you, or do something like this:

#split the query string by key/value pairs
my @unparsed = split(/&/, $query);
for $pair(@unparsed) {
# split the key and value for each pair
my ($key, $value) = split(/=/, $pair);
#substitue pluses for spaces
if ($value =~ /\+/) { $value =~ s/\+/ /g; }
#look for hex values (this could be a better regex)
while ($value =~ /\%((\d¦\w)(\d¦\w))/g) {
my $val = $1;
my $hex_val = hex($val);
#replace all occurrences of the hex value with the character
$value =~ s/%$val/chr($hex_val)/eg;
}
#store results in a hash
$params{$key} = $value;
}

energylevel

3:04 pm on May 11, 2004 (gmt 0)

10+ Year Member



thanks ...........