zoukankan      html  css  js  c++  java
  • php gzcompress() 和gzuncompress()函数实现字符串压缩

    当我们说到压缩,我们可能会想到文件压缩,其实,字符串也是可以压缩的。
    
    PHP提供了 gzcompress() 和gzuncompress() 函数:
    $string = “Lorem ipsum dolor sit amet, consectetur  adipiscing elit. Nunc ut elit id mi 
    ultricies  adipiscing. Nulla facilisi. Praesent pulvinar,  sapien vel feugiat vestibulum,
     nulla dui pretium orci,  non ultricies elit lacus quis ante. Lorem ipsum dolor  sit amet,
     consectetur adipiscing elit. Aliquam pretium ullamcorper urna quis iaculis. Etiam ac 
    massased turpis tempor luctus. Curabitur sed nibh eu elitmollis congue. Praesent ipsum diam, 
    consectetur vitae ornare a, aliquam a nunc. In id magna pellentesque tellus posuere 
    adipiscing. Sed non mi metus, at lacinia augue. Sed magna nisi, ornare in mollis in, 
    mollis sed nunc. Etiam at justo in leo congue mollis.Nullam in neque eget metus hendrerit
     scelerisque eu non enim. Ut malesuada lacus eu nulla bibendum  id euismod urna sodales. “;
    
    /*压缩字符串*/ 
    
    $compressed = gzcompress($string);  
    
    echo “Original size: “. strlen($string).” ”;  
    
    /* 输出原始大小 Original size: 800 */  
    
    echo “Compressed size: “. strlen($compressed).” ”;
    
     /* 输出压缩后的大小 Compressed size: 418 */  
    
    // 解压缩  
    
    $original = gzuncompress($compressed);  
    
    
    

  • 相关阅读:
    Leetcode 191.位1的个数 By Python
    反向传播的推导
    Leetcode 268.缺失数字 By Python
    Leetcode 326.3的幂 By Python
    Leetcode 28.实现strStr() By Python
    Leetcode 7.反转整数 By Python
    Leetcode 125.验证回文串 By Python
    Leetcode 1.两数之和 By Python
    Hdoj 1008.Elevator 题解
    TZOJ 车辆拥挤相互往里走
  • 原文地址:https://www.cnblogs.com/qhorse/p/6046087.html
Copyright © 2011-2022 走看看