downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.gzencode.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.zlib.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.gzencode.php',
   
1 => 'gzencode',
  ),
 
'up' =>
  array (
   
0 => 'ref.zlib.php',
   
1 => 'Zlib Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.gzdeflate.php',
   
1 => 'gzdeflate',
  ),
 
'next' =>
  array (
   
0 => 'function.gzeof.php',
   
1 => 'gzeof',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.gzencode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">gzencode</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">gzencode</span> &mdash; <span class="dc-title">Create a gzip compressed string</span></p>

 </div>

 <a name="function.gzencode.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><b>gzencode</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$data</tt></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$level</tt><span class="initializer"> = -1</span></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$encoding_mode</tt><span class="initializer"> = FORCE_GZIP</span></span>
  ]] )</div>

  <p class="para rdfs-comment">  
   This function returns a compressed version of the input
   <i><tt class="parameter">data</tt></i>
 compatible with the output of the
   <strong class="command">gzip</strong> program.
  </p>
  <p class="para">
   For more information on the GZIP file format, see the document:
   <a href="http://www.faqs.org/rfcs/rfc1952" class="link external">&raquo; GZIP file format specification
   version 4.3</a> (RFC 1952).
  </p>
 </div>


 <a name="function.gzencode.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">data</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The data to encode.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">level</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The level of compression. Can be given as 0 for no compression up to 9
       for maximum compression. If not given, the default compression level will
       be the default compression level of the zlib library.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">encoding_mode</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       The encoding mode. Can be <b><tt class="constant">FORCE_GZIP</tt></b> (the default)
       or <b><tt class="constant">FORCE_DEFLATE</tt></b>.
      </p>
      <p class="para">
       If you use <b><tt class="constant">FORCE_DEFLATE</tt></b>, you get a standard zlib
       deflated string (inclusive zlib headers) after the gzip file header but
       without the trailing crc32 checksum.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.gzencode.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   The encoded string, or <b><tt class="constant">FALSE</tt></b> if an error occurred.
  </p>
 </div>


 <a name="function.gzencode.changelog"></a><div class="refsect1 changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   </p><table class="doctable informaltable">
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">4.2.0</td>
       <td align="left">
        The <i><tt class="parameter">encoding_mode</tt></i>
 parameter was added
       </td>
      </tr>

     </tbody>
   
   </table>
<p>
  </p>
 </div>


 <a name="function.gzencode.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   The resulting data contains the appropriate headers and data
   structure to make a standard .gz file, e.g.:
   </p><div class="example">
    <p><b>Example #1 Creating a gzip file</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #DD0000">"bigfile.txt"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$gzdata&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">gzencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">9</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"bigfile.txt.gz"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$gzdata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.gzencode.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.gzdecode.php" class="function" rel="rdfs-seeAlso">gzdecode()</a> - Decodes a gzip compressed string</li>
    <li class="member"><a href="function.gzdeflate.php" class="function" rel="rdfs-seeAlso">gzdeflate()</a> - Deflate a string</li>
    <li class="member"><a href="function.gzinflate.php" class="function" rel="rdfs-seeAlso">gzinflate()</a> - Inflate a deflated string</li>
    <li class="member"><a href="function.gzuncompress.php" class="function" rel="rdfs-seeAlso">gzuncompress()</a> - Uncompress a compressed string</li>
    <li class="member"><a href="function.gzcompress.php" class="function" rel="rdfs-seeAlso">gzcompress()</a> - Compress a string</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites