Solved

getting rid of...

Posted on 1998-06-22
7
177 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 video discusses moving either the default database or any database to a new volume.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now