Skrevet av Emne: How to URL encode a string in Perl  (Lest 4290 ganger)

ATC

  • Gjest
How to URL encode a string in Perl
« på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • When passing "weird" characters in web forms, URLs etc. the HTTP standard requires them to be encoded as hex ASCII codes with leading % signs. Example:

    "my fun stuff" = "my%20fun%20stuff"



    ATC

    • Gjest
    [Solved] How to URL encode a string in Perl
    « Svar #1 på: 27. ſeptember 2008, 18:24 pm »
  • [applaud]0
  • [smite]0
  • Cast this regular expression on your string to encode it:

    $string =~ s/([^A-Za-z0-9\.])/sprintf("%%%02X", ord($1))/seg;