字符串压缩 (转)
當我們說到壓縮,我們可能會想到文件壓縮,其實,字符串也是可以壓縮的。PHP提供了?gzcompress()?和gzuncompress()?函數:? Php代碼? $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?massa?? sed?turpis?tempor?luctus.?Curabitur?sed?nibh?eu?elit?? mollis?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).”\n”;?? /*?輸出原始大小? Original?size:?800? */?? echo?“Compressed?size:?“.?strlen($compressed).”\n”;?? /*?輸出壓縮后的大小? Compressed?size:?418? */?? //?解壓縮?? $original?=?gzuncompress($compressed); ? 幾乎有50% 壓縮比率。同時,你還可以使用?gzencode()?和?gzdecode()?函數來壓縮,只不用其用了不同的壓縮算法。
轉載于:https://www.cnblogs.com/xingmeng/p/3198631.html
總結
- 上一篇: cookie欺骗
- 下一篇: Linux下访问光盘数据