base64_encode()
base64_encode() — Encodes data with MIME base64.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.
Signature
base64_encode(string $string): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The data to encode. |
Return value
The encoded data, as a string.
Example
A runnable snippet:
$str = 'This is an encoded string'; echo base64_encode($str);
Output:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==
See also
base64_decode(), chunk_split(), convert_uuencode()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page base64_encode() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.