Solved

getting rid of...

Posted on 1998-06-22
7
196 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?
0
Comment
Question by:idadan
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:idadan
ID: 1207963
Edited text of question
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1207964
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/\\\+/+/;

0
 

Author Comment

by:idadan
ID: 1207965
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.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1207966
If the question is why is it changing any character NOT found in a word to a percent sign followed by the hex string of that character (high nybble first?) Because that is exactly what

s/([^\w ])/'%'.unpack('H*',$1)/eg;

does!!!!  (In case you don't know, the ascii code for a question mark is 3f)

0
 

Author Comment

by:idadan
ID: 1207967
Great, thanks for your help.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1207968
     
0
 
LVL 84

Expert Comment

by:ozo
ID: 1207969
$Subject=~s/%(\w\w)/pack('H*',$1)/eg;
#should have changed "What%27s up%3f" back to "What's up?"
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question