PHP 的 Windows 版本已经内置该扩展模块的支持。您无需加载任何附加的扩展库即可使用这些函数。 注: Builtin support for zlib on Windows is available with PHP 4.3.0. 例子 1. Small Zlib Example<?php$filename = tempnam('/tmp', 'zlibtest') . '.gz'; echo "<html>\n<head></head>\n<body>\n<pre>\n"; $s = "Only a test, test, test, test, test, test, test, test!\n";// open file for writing with maximum compression $zp = gzopen($filename, "w9");// write string to file gzwrite($zp, $s);// close file gzclose($zp);// open file for reading $zp = gzopen($filename, "r");// read 3 char echo gzread($zp, 3);// output until end of the file and close it. gzpassthru($zp); gzclose($zp);echo "\n";// open file and print content (the 2nd time). if (readgzfile($filename) != strlen($s)) { echo "Error with zlib functions!"; } unlink($filename); echo "</pre>\n</body>\n</html>\n";?>
to lawyu(雨淋漓) ( ) :你的例子是用的文件,而我返回的压缩值是放在一个变量里边了,根本没有文件!
目录 gzclose -- Close an open gz-file pointer *** gzcompress -- Compress a string gzdeflate -- Deflate a string *** gzencode -- Create a gzip compressed string gzeof -- Test for end-of-file on a gz-file pointer gzfile -- Read entire gz-file into an array gzgetc -- Get character from gz-file pointer gzgets -- Get line from file pointer gzgetss -- Get line from gz-file pointer and strip HTML tags *** gzinflate -- Inflate a deflated string gzopen -- Open gz-file gzpassthru -- Output all remaining data on a gz-file pointer gzputs -- Alias of gzwrite() gzread -- Binary-safe gz-file read gzrewind -- Rewind the position of a gz-file pointer gzseek -- Seek on a gz-file pointer gztell -- Tell gz-file pointer read/write position *** gzuncompress -- Uncompress a deflated string gzwrite -- Binary-safe gz-file write readgzfile -- Output a gz-file zlib_get_coding_type -- Returns the coding type used for output compression
注: Builtin support for zlib on Windows is available with PHP 4.3.0.
例子 1. Small Zlib Example<?php$filename = tempnam('/tmp', 'zlibtest') . '.gz';
echo "<html>\n<head></head>\n<body>\n<pre>\n";
$s = "Only a test, test, test, test, test, test, test, test!\n";// open file for writing with maximum compression
$zp = gzopen($filename, "w9");// write string to file
gzwrite($zp, $s);// close file
gzclose($zp);// open file for reading
$zp = gzopen($filename, "r");// read 3 char
echo gzread($zp, 3);// output until end of the file and close it.
gzpassthru($zp);
gzclose($zp);echo "\n";// open file and print content (the 2nd time).
if (readgzfile($filename) != strlen($s)) {
echo "Error with zlib functions!";
}
unlink($filename);
echo "</pre>\n</body>\n</html>\n";?>
gzclose -- Close an open gz-file pointer
*** gzcompress -- Compress a string
gzdeflate -- Deflate a string
*** gzencode -- Create a gzip compressed string
gzeof -- Test for end-of-file on a gz-file pointer
gzfile -- Read entire gz-file into an array
gzgetc -- Get character from gz-file pointer
gzgets -- Get line from file pointer
gzgetss -- Get line from gz-file pointer and strip HTML tags
*** gzinflate -- Inflate a deflated string
gzopen -- Open gz-file
gzpassthru -- Output all remaining data on a gz-file pointer
gzputs -- Alias of gzwrite()
gzread -- Binary-safe gz-file read
gzrewind -- Rewind the position of a gz-file pointer
gzseek -- Seek on a gz-file pointer
gztell -- Tell gz-file pointer read/write position
*** gzuncompress -- Uncompress a deflated string
gzwrite -- Binary-safe gz-file write
readgzfile -- Output a gz-file
zlib_get_coding_type -- Returns the coding type used for output compression
<?php
$s = "请问怎么解压缩一个非文件,就是一个变量,变量的值是一个压缩的咚咚,我怎么解压缩这个变量,
是不是把它放到内存中,最后删除这个内存变量?具体的有法子做吗?";$z = gzcompress($s);
echo gzuncompress($z);
?>