Posted By

apphp-snippets on 02/19/13


Tagged

php encode base64


Versions (?)

Base64 Encode and Decode String in PHP


 / Published in: PHP
 

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

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

  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. ?>

Report this snippet  

You need to login to post a comment.