Talk about a confusing-looking hack, but this one seemed to work to take
care of the hex values.
$value =~ s/(\%){1}(\d|[a-fA-F]){1}(\d|[a-fA-F]){1}/ /g;
Scot R.
inSite
-----Original Message-----
From: steve ryan [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 08, 2003 5:38 PM
To: [EMAIL PROTECTED]
Subject: Simple character replace problem
Hi,
I was wondering if someone could help me with this as it is driving me
insane!
I have a CGI script which writes a series of form fields to a tab-delimited
file.
I read in the fields and then replace certain characters (like commas etc.)
The problem is -
1. My "+" symbols are not being replaced (i.e. the spaces in the form)
2. My HEX/Ascii conversion isn't working (i.e. i am getting things like %2C)
Here is my conversion code -
# replace new lines with a space
$value =~ s/\n/ /g;
# remove hard returns
$value =~ s/\r//g;
# remove ^M's
$value =~ s/\cM//g;
# replace commas with a space
$value =~ s/,/ /g;
# replace + with a space
$value =~ tr/+/ /;
# or sometimes $value =~ s/\+/ /g;
# replace hex pairs back to it's acsii equivalent
$value =~
s/%([\da-fA-F][\da-fA-F])/pack("C",hex($1))/eg;
Any idea why this isn't working?
Thanks,
Steve
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]