示例一(用php的內置壓縮函數)
<?PHP
if(Extension_Loaded(’zlib’)) Ob_Start(’ob_gzhandler’);
Header("Content
?>
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<meta http
<title>無標題文檔</title>
</head>
<body>
<?php
for($i=
echo ’Hello World!’;
}
?>
</body>
</html>
<?PHP
if(Extension_Loaded(’zlib’)) Ob_End_Flush();
?>
示例二(自寫函數)
<?php ob_start(’ob_gzip’); ?>
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<meta http
<title>無標題文檔</title>
</head>
<body>
</body>
</html>
<?php
ob_end_flush();
//壓縮函數
function ob_gzip($content){
if(!headers_sent()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"]
$content = gzencode($content
header("Content
header("Vary: Accept
header("Content
}
return $content;
}
?>
From:http://tw.wingwit.com/Article/program/PHP/201311/20896.html