加密扩展
变量与类型相关扩展
其它基本扩展
Lua
  • sp
  • 简介
  • 安装/配置
  • 预定义常量
  • 数据结构
  • 迭代器
  • 接口
  • 异常
  • SPL 函数
    • class_​implements
    • class_​parents
    • class_​uses
    • iterator_​apply
    • iterator_​count
    • iterator_​to_​array
    • spl_​autoload_​call
    • spl_​autoload_​extensions
    • spl_​autoload_​functions
    • spl_​autoload_​register
    • spl_​autoload_​unregister
    • spl_​autoload
    • spl_​classes
    • spl_​object_​hash
    • spl_​object_​id
  • 文件处理
    • SplFileInfo
      • public __construct ( string $file_name )
      • public getATime ( void ) : int
      • public getBasename ([ string $suffix ] ) : string
      • public getCTime ( void ) : int
      • public getExtension ( void ) : string
      • public getFileInfo ([ string $class_name ] ) : SplFileInfo
      • public getFilename ( void ) : string
      • public getGroup ( void ) : int
      • public getInode ( void ) : int
      • public getLinkTarget ( void ) : string
      • public getMTime ( void ) : int
      • public getOwner ( void ) : int
      • public getPath ( void ) : string
      • public getPathInfo ([ string $class_name ] ) : SplFileInfo
      • public getPathname ( void ) : string
      • public getPerms ( void ) : int
      • public getRealPath ( void ) : string
      • public getSize ( void ) : int
      • public getType ( void ) : string
      • public isDir ( void ) : bool
      • public isExecutable ( void ) : bool
      • public isFile ( void ) : bool
      • public isLink ( void ) : bool
      • public isReadable ( void ) : bool
      • public isWritable ( void ) : bool
      • public openFile ([ string $open_mode = "r" [, bool $use_include_path = FALSE [, resource $context = NULL ]]] ) : SplFileObject
      • public setFileClass ([ string $class_name = "SplFileObject" ] ) : void
      • public setInfoClass ([ string $class_name = "SplFileInfo" ] ) : void
      • public __toString ( void ) : string
    • SplFileObject
    • SplTempFileObject
  • 各种类及接口
XML操作
影响 PHP 行为的扩展
文本处理
图像生成和处理
文件系统
数据库扩展
pdo
数学
日期与时间
压缩与归档
其它服务
zlib

This module enables you to transparently read and write gzip (.gz) compressed files, through versions of most of the filesystem functions which work with gzip-compressed files (and uncompressed files, too, but not with sockets).

Note:

Version 4.0.4 introduced a fopen-wrapper for .gz-files, so that you can use a special zlib: URL to access compressed files transparently using the normal f*() file access functions if you prefix the filename or path with zlib: when calling fopen(). This feature requires a C runtime library that provides the fopencookie() function. Up to now the GNU libc seems to be the only library that provides this feature.

In PHP 4.3.0, zlib: has been changed to compress.zlib:// to prevent ambiguities with filenames containing ':' characters. The fopencookie() function is no longer required. More information is available in the section about zlib://.

例子

This example opens a temporary file and writes a test string to it, then it prints out the content of this file twice.

<?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";

?>
// Perform GZIP compression:
$deflateContext = deflate_init(ZLIB_ENCODING_GZIP);
$compressed = deflate_add($deflateContext, "Data to compress", ZLIB_NO_FLUSH);
$compressed .= deflate_add($deflateContext, ", more data", ZLIB_NO_FLUSH);
$compressed .= deflate_add($deflateContext, ", and even more data!", ZLIB_FINISH);?>

// Perform GZIP decompression:
$inflateContext = inflate_init(ZLIB_ENCODING_GZIP);
$uncompressed = inflate_add($inflateContext, $compressed, ZLIB_NO_FLUSH);
$uncompressed .= inflate_add($inflateContext, NULL, ZLIB_FINISH);
echo $uncompressed;
//
// Data to compress, more data, and even more data!