php8.5
Home/ Manual/ url / functions/ base64_encode

base64_encode

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Encodes data with MIME base64

Description

base64_encode(string $string): string

Encodes the given string with base64.

This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.

Base64-encoded data takes about 33% more space than the original data.

Parameters

string

The data to encode.

Return Values

The encoded data, as a string.

Examples

base64_encode() example

php
<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>

The above example will output:

output
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==

See Also

Source: reference/url/functions/base64-encode.xml · from the official PHP manual (php/doc-en)