How to Base64 Encode\Decode a String in PHP

Encode text in base64:

$string = "Text_To_Encode";
$encoded = base64_encode($string);
echo "Encoded text is: ".htmlspecialchars($encoded);

Example output:

Encoded text is: VGV4dF9Ub19FbmNvZGU=

Decode base64 encoded text:

$string = "VGV4dF9Ub19FbmNvZGU=";
$decoded = base64_decode($string);
echo "Decoded text is: ".htmlspecialchars($decoded);

Example output:

Decoded text is: Text_To_Encode

More Related Posts