array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.base64-encode.php', 1 => 'base64_encode', ), 'up' => array ( 0 => 'ref.url.php', 1 => 'URL 函数', ), 'prev' => array ( 0 => 'function.base64-decode.php', 1 => 'base64_decode', ), 'next' => array ( 0 => 'function.get-headers.php', 1 => 'get_headers', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/url/functions/base64-encode.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
base64_encode — 使用 MIME base64 对数据进行编码
使用 base64 对 string
进行编码。
设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层传输,例如电子邮件的主体。
Base64-encoded 数据要比原始数据多占用 33% 左右的空间。
string
要编码的数据。
编码后的字符串数据。
示例 #1 base64_encode() 示例
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
以上示例会输出:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==