Snippet : Base64 Encode and Base64 Decode in PHP

This snippet helps you to encode and decode your text with base64.
Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding. - Wikipedia
Encoding


  1. <?php
  2. function Base64Encode($text){
  3.     $base64_en = base64_encode($text);
  4.     $base64_en = strtr($base64_en, '+/=', '-_,');
  5.     return $base64_en;
  6. }
  7. echo Base64Encode("Mohamed Shimran");
  8. ?>
Return

TW9oYW1lZCBTaGltcmFu


Replace Mohamed Shimran with the text you want to encode



Decoding


  1. <?php
  2. function Base64Decode($text){
  3.     $base64_de = strtr($text, '-_,', '+/=');
  4.     $base64_de = base64_decode($base64_de);
  5.     return $base64_de;
  6. }
  7. echo Base64Decode("TW9oYW1lZCBTaGltcmFu");
  8. ?>
Return

Mohamed Shimran

Replace TW9oYW1lZCBTaGltcmFu with the encoded..

Post a Comment

Note: Only a member of this blog may post a comment.