Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

How to escape special characters correctly for a URL

by silent11 (Vicar)
on May 27, 2004 at 13:34 UTC ( #356890=perlquestion: print w/replies, xml ) Need Help??
silent11 has asked for the wisdom of the Perl Monks concerning the following question:

What I have: Fútbol con Mayte introducción al fútbol

What I need: F%C3%BAtbol+con+Mayte+introducci%C3%B3n+al+f%C3%BAtbol

What I get with URI::Escape : F%FAtbol%20con%20Mayte%20introducci%F3n%20al%20f%FAtbol

What module can I use to convert what I have, a string with those funky characters, into what I need, an escaped sequence? URI::Escape isn't doing the job for me, I'm sure it is doing it's job correctly, I'm just misusing the module. Any Ideas?

  • Comment on How to escape special characters correctly for a URL

Replies are listed 'Best First'.
Re: How to escape special characters correctly for a URL
by snadra (Scribe) on May 27, 2004 at 14:57 UTC
    URI::Escape is using RFC2396 and updated by RFC2732 for encoding and decoding characters that are not alphanumeric (a-zA-Z_0-9 or simply \w).
    Try to figure out what kind of encoding you have to use. Maybe there is an existing module. If not a definition will make it easier for you to write one.

Re: How to escape special characters correctly for a URL
by Roy Johnson (Monsignor) on May 27, 2004 at 14:21 UTC
    You're not misusing the module; it seems you don't want the module. If you pass your "what I need" to uri_unescape, you get a mess, so it's clearly not compatible. (At the very least, the spaces-for-pluses translation isn't normal.)

    I think you're going to have to roll your own. How did you determine what you need?

    The PerlMonk tr/// Advocate

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://356890]
Approved by Corion
[Discipulus]: context pra? tk html console naturla language?
[Corion]: Or HTML color like #c0ffee ?
[pra]: Perl/Tk. I want to input a file that will contain color names, but users might not know what names are valid

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2017-10-17 11:41 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (226 votes). Check out past polls.