PHP base64_decode编码的数据进行解码

2015-04-13 分类:js,php,html, php 阅读(9934) 评论(3)

base64_decode ― 对使用 MIME base64 编码的数据进行解码

说明
string base64_decode ( string $encoded_data )
base64_decode() 对 encoded_data 进行解码,返回原始数据,失败则返回 FALSE。返回的数据可能是二进制的。

Example #1 base64_decode() 示例

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

此示例将显示:

This is an encoded string

笔记
PHP base64_decode note #1
base64_decode seems to fail when decoding big files/strings. I had an issue decoding a 7MB image file. Here is a solution that worked for me:

$decodedstring=base64_decode(chunk_split($encodedstring));
PHP base64_decode note #2
If you want to save data that is derived from a Javascript canvas.toDataURL() function, you have to convert blanks into plusses. If you do not do that, the decoded data is corrupted:

<?php
  $encodedData = str_replace(' ','+',$encodedData);
  $decocedData = base64_decode($encodedData);
?>

merci..........
PHP base64_decode note #3
If you want to save data that is derived from a Javascript canvas.toDataURL() function, you have to convert blanks into plusses. If you do not do that, the decoded data is corrupted:

<?php
  $encodedData = str_replace(' ','+',$encodedData);
  $decocedData = base64_decode($encodedData);
?>

PHP base64_decode note #4
I had some trouble trying to let base64_decode decode base64-strings longer than ~5k chars.

The base64-decoding function is a homomorphism between modulo 4 and modulo 3-length segmented strings. That motivates a divide and conquer approach: Split the encoded string into substrings counting modulo 4 chars, then decode each substring and concatenate all of them.

Then instead of

<?php $decoded = base64_decode($encoded); ?>

for big $encoded strings, it's saver to use

<?php 
$decoded = ""; 
for ($i=0; $i < ceil(strlen($encoded)/256); $i++) 
   $decoded = $decoded . base64_decode(substr($encoded,$i*256,256)); 
?>

where 256 can be replaced by a sufficiently small modulo 4 natural.

1 2 3 4

您可能也喜欢:

防F12扒代码:按下F12关闭当前页面

只要按下那神秘的审查元素、按下那神秘的F12键,奇迹出现了!网站变成了空白页,可谓杀Bug放火必备佳品! 一段JavaScript代码即可实现上述功能,插入到 footer.php 的 前: <script>function fuckyou(){ window.close(); //...

more

网站变灰代码-悼念遇难同胞

如果你也想和我一样网站变灰来悼念遇难的同胞 以下css代码加在你的css样式文件里面就可以了 html { filter: grayscale(100%); -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -m...

more

gravatar头像被墙无法打开解决办法

本站以前介绍过关于Gravatar,这篇文章主要解决wordpress的Gravatar头像被墙后导致评论头像等无法打开的问题.Gravatar头像已经成为了主流的通用头像,论坛,博客程序等.由于服务器在国外,http的头像图片就悲剧了~ 我一直不提倡用缓存的方法将图片缓存到服务器,这样一来图片一...

more

评论&留言
欢迎新朋友你的到来!
已经有3 条评论抢在你前面了~
昵称
邮箱
网站

  1. xyayy
    爱在发烧 官方

    This is a great idea. 这只是一个测试

    #1
    回复
  2. 小白

    留下脚印 有时间过来补

    #2
    回复
    • xyayy
      发烧爱 官方 回复

      @小白 客气啦

切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册