Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Tuesday, February 6, 2018

Encode and decode string with Base64 using PHP

base64_encode — Encodes data with MIME base64
string base64_encode ( $string )
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.

Base64_encode:
<?php
$plainText = 'http://www.phpjavascript.com/';
$base64 = base64_encode($plainText);
$base64url = strtr($base64, '+/=', '-_,');
echo $base64url;
?>
Result:
aHR0cDovL3d3dy5waHBqYXZhc2NyaXB0LmNvbS8,

Base64_decode:
<?php
$plainText = "aHR0cDovL3d3dy5waHBqYXZhc2NyaXB0LmNvbS8,";
$base64url = strtr($plainText, '-_,', '+/=');
$base64 = base64_decode($base64url);
echo $base64;
?>
Result:
http://www.phpjavascript.com/

7 comments:

  1. Thank you so much for providing such a useful content. Digital Signature Certificate

    ReplyDelete
  2. Thanks for sharing such great piece of information with us. Digital Signature Certificate

    ReplyDelete
  3. I really enjoyed reading your blog, you have lots of great content. Please visit here:
    Private detective agency in Mumbai

    ReplyDelete
  4. I am very grateful you did share your knowledge here. It is an excellent post.sharing this sort of educational posts. Class 2 Digital Signature Certificate

    ReplyDelete
  5. Thanks for sharing such great piece of information with us. Class 2 Digital Signature Certificate

    ReplyDelete

More Posts

FOLLOW