示例一(用php的内置压缩函数)
<?PHP
if(Extension_Loaded(’zlib’))Ob_Start(’ob_gzhandler’);
Header("Contenttype:text/html");
?>
<!DOCTYPEhtmlPUBLIC"//WC//DTDXHTMLTransitional//EN""
<htmlxmlns="
<head>
<metahttpequiv="ContentType"content="text/html;charset=gb"/>
<title>无标题文档</title>
</head>
<body>
<?php
for($i=;$i<;$i++){
echo’HelloWorld!’;
}
?>
</body>
</html>
<?PHP
if(Extension_Loaded(’zlib’))Ob_End_Flush();
?>
示例二(自写函数)
<?phpob_start(’ob_gzip’);?>
<!DOCTYPEhtmlPUBLIC"//WC//DTDXHTMLTransitional//EN""
<htmlxmlns="
<head>
<metahttpequiv="ContentType"content="text/html;charset=gb"/>
<title>无标题文档</title>
</head>
<body>
</body>
</html>
<?php
ob_end_flush();
//压缩函数
functionob_gzip($content){
if(!headers_sent()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"]"gzip")){
$content=gzencode($content);
header("ContentEncoding:gzip");
header("Vary:AcceptEncoding");
header("ContentLength:"strlen($content));
}
return$content;
}
?>