We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

getting rid of...

idadan
idadan asked
on
Medium Priority
242 Views
Last Modified: 2010-03-04
I'm making a bbs and need advice on a bit of code.  Right now whenever anyone submits there post the subject looks like What%27s+up%3f instead of What's+up?  I use this to encode all white spaces to + signs
$Subject =~ s/([^\w ])/'%'.unpack('H*',$1)/eg;
$Subject =~ tr/ /+/;
and this to get it back from + signs to spaces
$Subject=~tr/+/ /;
$Subject=~s/%(\w\w)/pack('H*',$1)/eg;

Is this the reason all my non alphabetic and numeric characters endup like this?
Comment
Watch Question

Author

Commented:
Edited text of question

Commented:
You told it to!  If all you want to do is convert any white space to a + sign, just use

$Subject =~ s/\s+/+/;

That will take "What's     up?"  or "What's up?" and change it to "What's+up?"

Of course, then you have the problem of someone actually typing in '+', so preface the above line with

$Subject =~ s/\+/\\+/;

To undo that mess, use

$Subject =~ s/([^\\])\+/\1 /;
$Subject =~ s/\\\+/+/;

Author

Commented:
Ok, the question is why is it changing, say a, question mark to %3f NOT why is it changing + signs to " " and visa virsa.  Sorry for the misunderstanding.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Great, thanks for your help.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
     
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
$Subject=~s/%(\w\w)/pack('H*',$1)/eg;
#should have changed "What%27s up%3f" back to "What's up?"
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.