home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_8986c60cb05dccbb4290d38e4ebbeaad
< prev
next >
Wrap
Text File
|
2000-03-23
|
5KB
|
126 lines
<HTML>
<HEAD>
<TITLE>URI::Escape - Escape and unescape unsafe characters</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> URI::Escape - Escape and unescape unsafe characters</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#copyright">COPYRIGHT</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>URI::Escape - Escape and unescape unsafe characters</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use URI::Escape;
$safe = uri_escape("10% is enough\n");
$verysafe = uri_escape("foo", "\0-\377");
$str = uri_unescape($safe);</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>This module provides functions to escape and unescape URI strings as
defined by RFC 2396. URIs consist of a restricted set of characters,
denoted as <CODE>uric</CODE> in RFC 2396. The restricted set of characters
consists of digits, letters, and a few graphic symbols chosen from
those common to most of the character encodings and input facilities
available to Internet users:</P>
<PRE>
"A" .. "Z", "a" .. "z", "0" .. "9",
";", "/", "?", ":", "@", "&", "=", "+", "$", ",", # reserved
"-", "_", ".", "!", "~", "*", "'", "(", ")"</PRE>
<P>In addition any byte (octet) can be represented in a URI by an escape
sequence; a triplet consisting of the character ``%'' followed by two
hexadecimal digits. Bytes can also be represented directly by a
character using the US-ASCII character for that octet (iff the
character is part of <CODE>uric</CODE>).</P>
<P>Some of the <CODE>uric</CODE> characters are <EM>reserved</EM> for use as delimiters
or as part of certain URI components. These must be escaped if they are
to be treated as ordinary data. Read RFC 2396 for further details.</P>
<P>The functions provided (and exported by default) from this module are:</P>
<DL>
<DT><STRONG><A NAME="item_uri_escape">uri_escape($string, [$unsafe])</A></STRONG><BR>
<DD>
This function replaces all unsafe characters in the $string with their
escape sequences and returns the result.
<P>The <A HREF="#item_uri_escape"><CODE>uri_escape()</CODE></A> function takes an optional second argument that
overrides the set of characters that are to be escaped. The set is
specified as a string that can be used in a regular expression
character class (between [ ]). E.g.:</P>
<PRE>
"\x00-\x1f\x7f-\xff" # all control and hi-bit characters
"a-z" # all lower case characters
"^A-Za-z" # everything not a letter</PRE>
<P>The default set of characters to be escaped is all those which are
<EM>not</EM> part of the <CODE>uric</CODE> character class shown above.</P>
<P></P>
<DT><STRONG><A NAME="item_uri_unescape"><CODE>uri_unescape($string)</CODE></A></STRONG><BR>
<DD>
Returns a string with all %XX sequences replaced with the actual byte
(octet).
<P>This does the same as:</P>
<PRE>
$string =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;</PRE>
<P>but does not modify the string in-place as this RE would. Using the
<A HREF="#item_uri_unescape"><CODE>uri_unescape()</CODE></A> function instead of the RE might make the code look
cleaner and is a few characters less to type.</P>
<P>In a simple benchmark test I made I got something like 40% slowdown by
calling the function (instead of the inline RE above) if a few chars
where unescaped and something like 700% slowdown if none where. If
you are going to unescape a lot of times it might be a good idea to
inline the RE.</P>
<P></P></DL>
<P>The module can also export the <CODE>%escapes</CODE> hash which contains the
mapping from all 256 bytes to the corresponding escape code. Lookup
in this hash is faster than evaluating <A HREF="../../../lib/Pod/perlfunc.html#item_sprintf"><CODE>sprintf("%%%02X", ord($byte))</CODE></A>
each time.</P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P><A HREF="../../../site/lib/URI.html">the URI manpage</A></P>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>Copyright 1995-1998 Gisle Aas.</P>
<P>This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> URI::Escape - Escape and unescape unsafe characters</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>