Base64 Encode and Decode String in PHP


/ Published in: PHP
Save to your folder(s)

Encodes the given data with MIME base64. Base64-encoded data takes about 33% more space than the original data.


Copy this code and paste it in your HTML
  1. <?php
  2. function base64url_encode
  3. ($text){
  4. $base64 = base64_encode
  5. ($text);
  6. $base64url = strtr($base64, '+/=', '-_,');
  7. return $base64url;
  8. }
  9.  
  10. function base64url_decode
  11. ($text){
  12. $base64url = strtr($text, '-_,', '+/=');
  13. $base64 = base64_decode
  14. ($base64url);
  15. return $base64;
  16. }
  17. ?>

URL: http://www.apphp.com/index.php?snippet=php-base64-encode-and-decode-string

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.