array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.rawurlencode.php', 1 => 'rawurlencode', ), 'up' => array ( 0 => 'ref.url.php', 1 => 'URL 函数', ), 'prev' => array ( 0 => 'function.rawurldecode.php', 1 => 'rawurldecode', ), 'next' => array ( 0 => 'function.urldecode.php', 1 => 'urldecode', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/url/functions/rawurlencode.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
rawurlencode — 按照 RFC 3986 对 URL 进行编码
string
要编码的 URL。
返回字符串,此字符串中除了 -_.
之外的所有非字母数字字符都将被替换成百分号(%
)后跟两位十六进制数。这是在
» RFC 3986 中描述的编码,是为了保护原义字符以免其被解释为特殊的
URL 定界符,同时保护 URL 格式以免其被传输媒体(像一些邮件系统)使用字符转换时弄乱。
示例 #1 在 FTP URL 里包含一个密码
<?php
echo '<a href="ftp://user:', rawurlencode('foo @+%/'),
'@ftp.example.com/x.txt">';
?>
以上示例会输出:
<a href="ftp://user:foo%20%40%2B%25%2F@ftp.example.com/x.txt">
或者,如果你想通过 URL 的 PATH_INFO 构成部分去传递信息:
示例 #2 rawurlencode() 示例 2
<?php
echo '<a href="http://example.com/department_list_script/',
rawurlencode('sales and marketing/Miami'), '">';
?>
以上示例会输出:
<a href="http://example.com/department_list_script/sales%20and%20marketing%2FMiami">