Solved

getting rid of...

Posted on 1998-06-22
7
185 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

18 Experts available now in Live!

Get 1:1 Help Now