博客园  :: 首页  :: 新随笔  :: 订阅 订阅  :: 管理

PHP GZIP压缩+BASE64

Posted on 2017-02-04 09:58  PHP-张工  阅读(662)  评论(0编辑  收藏  举报
<?php

$str = '
{"pf":"AC25c","dt":"2017-02-04 09:49:49","wd":180,"lq":115,"c1":213,"c2":223,"c3":212,"c4":215,"c5":245,"f1":250},
{"pf":"AC25c","dt":"2017-02-04 09:52:09","wd":175,"lq":111,"c1":238,"c2":235,"c3":236,"c4":245,"c5":209,"f1":221},
{"pf":"AC25c","dt":"2017-02-04 09:52:51","wd":170,"lq":114,"c1":233,"c2":210,"c3":226,"c4":235,"c5":204,"f1":228}
';

echo '原始字符:' . strlen($str);
echo '<br>';
echo $str;
echo '<hr>';

$zip_str = gzencode($str);
echo '压缩字符:' . strlen($zip_str);
echo '<br>';
echo $zip_str;
echo '<hr>';

$base64_str = base64_encode($zip_str);
echo 'base64:' . strlen($base64_str);
echo '<br>';
echo $base64_str;
echo '<hr>';

// 解压
$s = base64_decode($base64_str);
$s = gzdecode($s);
echo '获取字符:' . strlen($s);
echo '<br>';
echo $s;
echo '<hr>';