Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

base64_encode()

Encode arbitrary bytes as Base64 text for a text-only field.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

base64_encode(string $string): string

Encode arbitrary bytes as Base64 text for a text-only field. Three input bytes yield four characters, and the final group may carry equals-sign padding. The standard alphabet includes plus and slash, so encode the result appropriately before embedding it in a URL component.

Signature

base64_encode(string $string): string

Example output

["","YQ==","+/8="]

Examples

<?php
echo json_encode([base64_encode(""),base64_encode("a"),base64_encode("\xFB\xFF")],JSON_UNESCAPED_SLASHES);

Result

["","YQ==","+/8="]

Sources