zhaoJian's Tech Notes

PHP Code for Base64 Encoding and Decoding

Technology ~601 words · 2 min read - views

In PHP, we can directly use PHP’s built-in functions base64_encode() and base64_decode() for encoding and decoding. Let’s get straight to the point:

Example 1. base64_encode() example

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

This example will display: VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==

Example 2. base64_decode() example

<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>

This example will display: This is an encoded string

PHP parameter integration.

<?php
$str = $url;
echo base64_decode($str);
?>
Share:

Comments