<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >rawurlencode</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="URL 函数" HREF="ref.url.html"><LINK REL="PREVIOUS" TITLE="rawurldecode" HREF="function.rawurldecode.html"><LINK REL="NEXT" TITLE="urldecode" HREF="function.urldecode.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.rawurldecode.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.urldecode.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.rawurlencode" ></A >rawurlencode</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN235923" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >rawurlencode -- 按照 RFC 1738 对 URL 进行编码</DIV ><DIV CLASS="refsect1" ><A NAME="AEN235926" ></A ><H2 >说明</H2 >string <B CLASS="methodname" >rawurlencode</B > ( string str )<BR ></BR ><P > 返回字符串,此字符串中除了 <TT CLASS="literal" >-_.</TT > 之外的所有非字母数字字符都将被替换成百分号(<TT CLASS="literal" >%</TT >)后跟两位十六进制数。这是在 RFC 1738 中描述的编码,是为了保护原义字符以免其被解释为特殊的 URL 定界符,同时保护 URL 格式以免其被传输媒体(像一些邮件系统)使用字符转换时弄乱。例如,如果你想在 FTP 的 URL 中包含密码: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN235938" ></A ><P ><B >例 1. <B CLASS="function" >rawurlencode()</B > 示例 1</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">echo </font><font color="#DD0000">'<a href="ftp://user:'</font><font color="#007700">, </font><font color="#0000BB">rawurlencode</font><font color="#007700">(</font><font color="#DD0000">'foo @+%/'</font><font color="#007700">),<br /> </font><font color="#DD0000">'@ftp.example.com/x.txt">'</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > 或者,如果你想通过 URL 的 PATH_INFO 构成部分去传递信息: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN235944" ></A ><P ><B >例 2. <B CLASS="function" >rawurlencode()</B > 示例 2</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">echo </font><font color="#DD0000">'<a href="http://example.com/department_list_script/'</font><font color="#007700">,<br /> </font><font color="#0000BB">rawurlencode</font><font color="#007700">(</font><font color="#DD0000">'sales and marketing/Miami'</font><font color="#007700">), </font><font color="#DD0000">'">'</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > 参见 <A HREF="function.rawurldecode.html" ><B CLASS="function" >rawurldecode()</B ></A >、<A HREF="function.urldecode.html" ><B CLASS="function" >urldecode()</B ></A >、<A HREF="function.urlencode.html" ><B CLASS="function" >urlencode()</B ></A > 与 <A HREF="http://www.faqs.org/rfcs/rfc1738" TARGET="_top" >RFC 1738</A >。 </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.rawurldecode.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.urldecode.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >rawurldecode</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.url.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >urldecode</TD ></TR ></TABLE ></DIV ></BODY ></HTML >