关于php压缩和解压缩

yunfeifan 2005-05-12 12:00:43
请问怎么解压缩一个非文件,就是一个变量,变量的值是一个压缩的咚咚,我怎么解压缩这个变量,
是不是把它放到内存中,最后删除这个内存变量?具体的有法子做吗?
...全文
270 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2005-05-12
  • 打赏
  • 举报
回复
有函数,见手册
xuzuning 2005-05-12
  • 打赏
  • 举报
回复
例:
<?php
$s = "请问怎么解压缩一个非文件,就是一个变量,变量的值是一个压缩的咚咚,我怎么解压缩这个变量,
是不是把它放到内存中,最后删除这个内存变量?具体的有法子做吗?";

$z = gzcompress($s);
echo gzuncompress($z);
?>
xuzuning 2005-05-12
  • 打赏
  • 举报
回复
目录
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
yunfeifan 2005-05-12
  • 打赏
  • 举报
回复
to lawyu(雨淋漓) ( ) :

你的例子是用的文件,而我返回的压缩值是放在一个变量里边了,根本没有文件!
lawyu 2005-05-12
  • 打赏
  • 举报
回复
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";

?>
yunfeifan 2005-05-12
  • 打赏
  • 举报
回复
to 楼上两位:

是gz 那一套马?我光找到压缩的gzencode() ,没有看到解压缩的函数!
lawyu 2005-05-12
  • 打赏
  • 举报
回复
Zlib Compression Functions

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧