Location: PHPKode > projects > PHP SiteBuilder > include/function.gzencode.php
<?php
/**
 * Emulate gzencode function for PHP4 version < 4.0.4
 *
 * @author	Tobias H. Michaelsen
 * @date	2001-10-16
 * @param	string	$data
 * @param	integer	$level	Compression level; 0 = none, 9 = max.
 * @return	Compressed data on success, false otherwise.
 *
 * $Id: function.gzencode.php,v 1.1 2001/10/16 00:49:51 zaiborg Exp $
 */ 
if (function_exists('gzencode')) return;
function gzencode($data, $level = 9)
{
    if (!extension_loaded('zlib') or !function_exists('gzcompress') {
        return false;
    }
    
    if ($compressed = gzcompress($data, $level)) {
        $crc = crc32($data);
	    $size = strlen($data);
		// Remove wrong crc:
        $compressed = substr($compressed, 0, -4);
        // Add gzip header:
        $compressed = "\x1f\x8b\x08\x00\x00\x00\x00\x00".$compressed;
		// Add new crc:
        $compressed .= pack('V', $crc);
        $compressed .= pack('V', $size);
    }

    return $compressed;
}
?>
Return current item: PHP SiteBuilder