例1,php 内置压缩函数的例子
/**
* php 内置函数压缩
* www.jbxue.com
*/
if(Extension_Loaded('zlib')) Ob_Start('ob_gzhandler');
Header("Content-type: text/html");
?>
php程序员的笔记for($i=0;$i<10000;$i++){
echo 'Hello World!';
}
?>
if(Extension_Loaded('zlib')) Ob_End_Flush();
?>
例2,自写函数实现压缩
自写函数压缩_www.jbxue.comob_end_flush();
//压缩函数
function ob_gzip($content){
if(!headers_sent()&&extension_loaded("zlib")&&strstr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip")){
$content = gzencode($content,9);
header("Content-Encoding: gzip");
header("Vary: Accept-Encoding");
header("Content-Length: ".strlen($content));
}
return $content;
}
?>