php provides a lot of string compression methods, below for everyone to compare the PHP string compression method, interested friends can refer to the following
The string compression method provided by PHP has 1.gzcompress-compress a string This function Compress the given string using The ZLIB data format. 2.gzencode-create a gzip compressed string This function returns a COMPR essed version of the input data compatible with the output of the program 3.gzdeflate-deflate a string This function compress the given string using the DEFLATE data format. 4.bzcompress-compresses a string into The BZIP2 encoded data bzcompress () compresses the specified string and returns the data in BZIP2 encoding. In the face of these four methods for compression comparison, respectively, the Chinese and English digital compression replication code is as follows: <?php $STR 1 = ' Layout 1 describes the layout, simply set the size and location of the element. EXT's layout system includes components, layouts, containers, and containers that are a special component that can manage the size and location of components. The container is dolayout to recalculate the layout and update the DOM. 2 manual layout is unnecessary and the framework will be automatically processed for you. '; $str 2 = '!@#$%^&* () qwertyuiopsdfghjkl!@#$%^&* () qwertyuiopsdfghjkl:zxcvbnma!@#$%^&* () ertyuiodfghjklxcvbnm@#$%^&* () rtyuiopd:zxcvbnm#!@#!@#$%^&* () qwertyuiopsdfghjkl:zxcvbnm-!@#$%^&* () Ertyuiodfghjklxcvbnm@#$%^&* () rtyuiopd$%^&* () ertyuiodfghj!@#$%^&* () qwertyuiopsdfghjkl:zxcvbnm]!@#$%^&* () ertyuiodfghjklxcvbnm@#$%^&* () rtyuiopdklxcvbnm@#$%^&* () rtyuiopdfghjklcvbnmfghjtyu%^& Rfghj4d56g7h8ui7h8ujirqwerqh8 '; echo ' <b> compress Chinese comparison </b><br><br> '; Compress_ Comp ($str 1, 1000); Compression 1000 times and decompression 1000 times comparison echo ' <b> compression English numeral comparison </b><br><br> '; Compress_comp ($ STR2, 1000); Compression 1000 times and decompression 1000 times comparison * Compression */ function Compress_comp ($str, $num) { $func _compress = Arra Y (' gzcompress ', ' gzencode ', ' gzdeflate ', ' bzcompress '); echo ' original: '. $str. ' <br><br> '; Echo ' Original size: '. strlen ($str). ' <br><br> '; for ($i =0, $length =count ($func _compress); $i < $length; $i + +) { $ StartTime = Get_microtime (); for ($j =0; $j < $num; $j + +) { switch ($func _compress[$i]) { case ' Gzcompress ': $mstr = gzcompress ($str, 9); //Decompression Method:gzuncompress break; case ' gzencode ': $mstr = Gzencode ($str, 9); Decompression method: Gzdecode php>=5.4 break; case ' gzdeflate ': $mstr = Gzdeflate ($str, 9); Decompression method:gzinflate break; case ' bzcompress ': $mstr = bzcompress ($str, 9); Decompression method:bzdecompress break; } } $endtime = get_microtime (); echo $func _compress[$i]. ' Size after compression: '. strlen ($MSTR). ' Time consuming: '. Round (($endtime-$starttime) *1000,5). ' Ms<br><br> '; } } /* Get microtime */ function get_microtime () { lis T ($usec, $sec) = Explode (', microtime (true)); return $usec + $sec; } ?> Execution result: copy code The code is as follows: Compress Chinese comparison Original: Layout 1 introduces the layout, simply to set the size and position of the element. EXT's layout system includes components, layouts, containers, and containers that are a special component that can manage the size and location of components. The container is dolayout to recalculate the layout and update the DOM. 2 manual layout is unnecessary and the framework will be automatically processed for you. Original size:328 gzcompress Compressed size: 251 time consuming:59.99994ms Gzencode Compressed size: 263 time consuming: 120.00012ms& nbsp GZDEFLAte compressed after size: 245 time-consuming:119.99989ms bzcompress compressed after size: 303 time-consuming:259.99999ms compression English numeral comparison Original:!@#$ %^&* () qwertyuiopsdfghjkl!@#$%^&* () qwertyuiopsdfghjkl:zxcvbnma!@#$%^&* () ERTYUIODFGHJKLXCVBNM@#$%^ &* () rtyuiopd:zxcvbnm#!@#!@#$%^&* () qwertyuiopsdfghjkl:zxcvbnm-!@#$%^&* () ERTYUIODFGHJKLXCVBNM@#$%^ &* () rtyuiopd$%^&* () ertyuiodfghj!@#$%^&* () qwertyuiopsdfghjkl:zxcvbnm]!@#$%^&* () ertyuiodfghjklxcvbnm@#$%^&* () rtyuiopdklxcvbnm@#$%^&* () rtyuiopdfghjklcvbnmfghjtyu%^& rfghj4d56g7h8ui7h8ujirqwerqh8 Original size:386 gzcompress Compressed size: 116 time consuming:50.00019ms Gzencode size after compression: 128 time consuming:99.9999ms Gzdeflate compressed after size: 110 time consuming:89.99991ms bzcompress Compressed size: 183 time consuming :210.00004ms can be concluded gzcompress speed is the fastest, high compression ratio. Gzdeflate Compression ratio is the highest, slightly slower than gzcompress Gzencode and Gzdeflate Close, gzdeflate slightly advantage Bzcompress speed is the slowest, compression rate is the slowest. Therefore recommends the use of gzcompress and gzdeflate.