Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Killing passed text...

Posted on 2000-03-21
7
Medium Priority
?
129 Views
Last Modified: 2010-03-05
This should be simple: is there a way to supress the output of the special escape characters in Perl?  In other words, if the user enters something like:

"I like to eat cheese!"

Can I keep it from being passed as:

"I+like+to+eat+cheese%21"?  

I need to output the text back to HTML, and it's obviously no good to me like this.  Do I just have to do an s///?  Or is there an easier way?
0
Comment
Question by:Raydot
7 Comments
 
LVL 4

Expert Comment

by:binkzz
ID: 2639788
You can't pass it any other way, but you can decode it by using two regular expressions:

$key=~s/\+/ /g;
$key=~s/%([0-9a-fA-f]{2})/pack("c",hex($1))/ge;

Binkzz
0
 
LVL 85

Expert Comment

by:ozo
ID: 2640105
why not pack("H*",$1)?
0
 
LVL 4

Expert Comment

by:binkzz
ID: 2640126
It works and doesn't particulary slow down the system
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Accepted Solution

by:
maneshr earned 200 total points
ID: 2640189
if you have the URI::Escape PERL module, try this....

if you dont, i would suggest that you install the same from www.cpan.org.

its very useful, since you dont have to worry about all the special characters to escape and unescape.

==============escape.pl
#!/usr/local/bin/perl

use URI::Escape;

$str="I like to eat cheese!";

print "Original string ",$str,"\n";
$safe = uri_escape($str);
print "After Escaping ",$safe,"\n";

$str  = uri_unescape($safe);
print "After Un-Escaping ",$str,"\n";
0
 
LVL 4

Expert Comment

by:binkzz
ID: 2640235
Can I just find out what's actually wrong with my solution?

Binkzz
0
 
LVL 3

Author Comment

by:Raydot
ID: 2640628
Who said there was anything wrong with your solution?  I think man and ozo are just offering alternatives.

I'll have to check for that URI::Escape module...Ozo, I don't really understand your pack solution.  Thanks!
0
 
LVL 3

Author Comment

by:Raydot
ID: 2810997
Did y'all think I forgot about this question?  Thanks for all your help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

783 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