<HTML ><HEAD ><TITLE >Compression functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="cpdf_add_annotation" HREF="function.cpdf-add-annotation.html"><LINK REL="NEXT" TITLE="gzclose" HREF="function.gzclose.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.cpdf-add-annotation.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.gzclose.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.zlib" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >VII. Compression functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN6246" ></A ><P > This module uses the functions of <A HREF="http://www.cdrom.com/pub/infozip/zlib/" TARGET="_top" >zlib</A > by Jean-loup Gailly and Mark Adler to transparently read and write gzip (.gz) compressed files. You have to use a zlib version >= 1.0.9 with this module. </P ><P > This module contains versions of most of the <A HREF="ref.filesystem.html" >filesystem</A > functions which work with gzip-compressed files (and uncompressed files, too, but not with sockets). </P ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="zlib-example" >Small code example</A ></H1 ><P > Opens a temporary file and writes a test string to it, then it prints out the content of this file twice. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. Small Zlib example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 <?php 3 $filename = tempnam('/tmp', 'zlibtest').'.gz'; 4 print "<html>\n<head></head>\n<body>\n<pre>\n"; 5 $s = "Only a test, test, test, test, test, test, test, test!\n"; 6 // open file for writing with maximum compression 7 $zp = gzopen($filename, "w9"); 8 // write string to file 9 gzwrite($zp, $s); 10 // close file 11 gzclose($zp); 12 // open file for reading 13 $zp = gzopen($filename, "r"); 14 // read 3 char 15 print gzread($zp, 3); 16 // output until end of the file and close it. 17 gzpassthru($zp); 18 print "\n"; 19 // open file and print content (the 2nd time). 20 if (readgzfile($filename) != strlen($s)) { 21 echo "Error with zlib functions!"; 22 } 23 unlink($filename); 24 print "<pre>\n</h1></body>\n</html>\n"; 25 ?> 26 </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.gzclose.html" >gzclose</A > — close an open gz-file pointer</DT ><DT ><A HREF="function.gzeof.html" >gzeof</A > — test for end-of-file on a gz-file pointer</DT ><DT ><A HREF="function.gzfile.html" >gzfile</A > — read entire gz-file into an array</DT ><DT ><A HREF="function.gzgetc.html" >gzgetc</A > — get character from gz-file pointer</DT ><DT ><A HREF="function.gzgets.html" >gzgets</A > — get line from file pointer</DT ><DT ><A HREF="function.gzgetss.html" >gzgetss</A > — get line from gz-file pointer and strip HTML tags</DT ><DT ><A HREF="function.gzopen.html" >gzopen</A > — open gz-file</DT ><DT ><A HREF="function.gzpassthru.html" >gzpassthru</A > — output all remaining data on a gz-file pointer</DT ><DT ><A HREF="function.gzputs.html" >gzputs</A > — write to a gz-file pointer</DT ><DT ><A HREF="function.gzread.html" >gzread</A > — Binary-safe gz-file read</DT ><DT ><A HREF="function.gzrewind.html" >gzrewind</A > — rewind the position of a gz-file pointer</DT ><DT ><A HREF="function.gzseek.html" >gzseek</A > — seek on a gz-file pointer</DT ><DT ><A HREF="function.gztell.html" >gztell</A > — tell gz-file pointer read/write position</DT ><DT ><A HREF="function.gzwrite.html" >gzwrite</A > — Binary-safe gz-file write</DT ><DT ><A HREF="function.readgzfile.html" >readgzfile</A > — output a gz-file</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.cpdf-add-annotation.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.gzclose.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >cpdf_add_annotation</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >gzclose</TD ></TR ></TABLE ></DIV ></BODY ></HTML >