CGI::Uricode - uri-en/decode a data for CGI program.
use CGI::Uricode qw(uri_encode uri_decode); my %input = ( 'name' => 'Masanori HATA', 'mail' => 'lovewing@dream.big.or.jp', 'home' => 'http://go.to/hata', ); my $encoded = uri_encode(%input); print $encoded; my %output = uri_decode($encoded); print 'name: ', $output{'name'}; # displays "name: Masanori HATA"
This module provides a set of functions for the data about application/x-www-form-urlencoded.
uri_encode(%param)
Exportable function. With the given $name and $value pairs, this function encode, construct and return a string of paired $name=$value strings those which are joined with "&" characters.
Though it is expressed virtually input into a hash (%), it is actually input into an arry (@). The Joined $name=$value strings in the output string will appear in the exact sequence of which they have been given. So you can control the order of the $name=$value strings in the output string. If you just give a real hash (%) to the function, the order of the $name=$value strings those which will appear in the output string will be random.
$encoded = uri_encode( name1 => value1, name2 => value2, (...) ); $encoded = "name1=value1&name2=value2&(...)";
The application/x-www-form-urlencoded is specified in the HTML 4 http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1.
With this function, by internally using the uri_escape() function, [SPACE] characters will be converted to "%20" strings to escape. This is normal manner in the HTTP "POST" method. To convert [SPACE] characters to "+" characters might occur in HTTP "GET" method to indicate the delimiters of query words, however this fuction won't do.
uri_decode($string)
Exportable function. This function decord and return the name and the value pairs from the given uri-encoded string. You might input them into a hash (%).
%param = uri_decode($encoded);
uri_escape($string)
Exportable function. This function escape the given string. The return value of the function is total number of escaped characters. The uri-escape is specified in the RFC 2396 http://www.ietf.org/rfc/rfc2396.txt (and it is partially updated by the RFC 2732). The module the URI::Escape manpage do the similar function.
uri_unescape($string)
Exportable function. This function unescape the given uri-escaped string. The return value of the function is total number of unescaped characters.
Masanori HATA http://go.to/hata (Saitama, JAPAN)
Copyright (c) 1999-2005 Masanori HATA. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.