{base64:string}

Description

Base64-encodes a string - the AA counterpart of PHP base64_encode(). It turns any text into the standard base64 alphabet (A-Z, a-z, 0-9, plus / and =), which is plain ASCII and safe to drop into a URL, an HTML attribute, a header or a filename. The output is padded with one or two = characters so its length is a multiple of four; an empty input gives an empty result. The input is not trimmed, so leading and trailing spaces are part of what gets encoded. This command only encodes; AA has no matching {base64decode} expression. A common pattern is to encode a hash or key and then cut it short with substr to make a compact opaque token.

Parameters

string optional default empty string

The text to encode. Any value is allowed - the result is plain ASCII safe for URLs, headers or attributes. Passed through untrimmed, so leading and trailing spaces are encoded. A literal colon in the text must be escaped as #: (otherwise it ends the parameter).

Examples

test{base64:hello}
ExpectedaGVsbG8=
ActualaGVsbG8=
Encode a plain word. The 8-char output is the standard base64 alphabet (A-Z a-z 0-9 + /), padded with = to a multiple of 4.
test{base64:Hello, World!}
ExpectedSGVsbG8sIFdvcmxkIQ==
ActualSGVsbG8sIFdvcmxkIQ==
Spaces, commas and other bytes encode fine. Length not a multiple of 3 gets one or two = pad characters.
test{base64:user@example.org}
ExpecteddXNlckBleGFtcGxlLm9yZw==
ActualdXNlckBleGFtcGxlLm9yZw==
Wrap a value that contains characters unsafe for a URL or header (here @ and .) into a single safe ASCII token.
test[{base64:}]
Expected[]
Actual[]
Empty input gives empty output (base64_encode of an empty string). Brackets are only there to make the empty result visible.
test{base64:a#:b}
ExpectedYTpi
ActualYTpi
A bare colon would end the parameter, so {base64:a:b} encodes only a. Escape the colon as #: to feed the literal text a:b. YTpi decodes back to a:b.
test{substr:{base64:session-key-7f3a}:2:8}
ExpectedVzc2lvbi
ActualVzc2lvbi
Real-world pattern: base64-encode a key or hash, then take a slice with substr to get a short opaque token (here 8 chars). Used for things like unsubscribe or confirmation links.