CGI-Utils

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    Aliases: url_encode()

  urlUnicodeEncode($str)
    Returns the fully URL-encoded version of the given string as unicode
    characters. It does not convert space characters to '+' characters.

    Aliases: url_unicode_encode()

  urlDecode($url_encoded_str)
    Returns the decoded version of the given URL-encoded string.

    Aliases: url_decode()

  urlUnicodeDecode($url_encoded_str)
    Returns the decoded version of the given URL-encoded string, with
    unicode support.

    Aliases: url_unicode_decode()

  urlEncodeVars($var_hash, $sep)
    Takes a hash of name/value pairs and returns a fully URL-encoded query
    string suitable for passing in a URL. By default, uses the newer
    separator, a semicolon, as recommended by the W3C. If you pass in a
    second argument, it is used as the separator between key/value pairs.

lib/CGI/Utils.pm  view on Meta::CPAN

        my ($self, $str) = @_;
        $str =~ s{([^A-Za-z0-9_])}{sprintf("%%u%04x", ord($1))}eg;
        return $str;
    }
    *url_unicode_encode = \&urlUnicodeEncode;

=pod

=head2 urlDecode($url_encoded_str)

Returns the decoded version of the given URL-encoded string.

Aliases: url_decode()

=cut
    sub urlDecode {
        my ($self, $str) = @_;
        $str =~ tr/+/ /;
        $str =~ s|%([A-Fa-f0-9]{2})|chr(hex($1))|eg;
        return $str;
    }
    *url_decode = \&urlDecode;

=pod

=head2 urlUnicodeDecode($url_encoded_str)

Returns the decoded version of the given URL-encoded string,
with unicode support.

Aliases: url_unicode_decode()

=cut
    sub urlUnicodeDecode {
        my ($self, $str) = @_;
        $str =~ tr/+/ /;
        $str =~ s|%([A-Fa-f0-9]{2})|chr(hex($1))|eg;
        $str =~ s|%u([A-Fa-f0-9]{2,4})|chr(hex($1))|eg;



( run in 0.393 second using v1.01-cache-2.11-cpan-1dc43b0fbd2 )