【phpob_start(ob_gzhandler)进行网页压缩_PHP教程】教程文章相关的互联网学习教程文章

PHP压缩CSS文件示例代码

// This defines the header typeheader("Content-type: text/css"); // Start the output bufferob_start("compress_css"); // Function which actually compress// The CSS filefunction compress_css($buffer){ /* remove comments */ $buffer = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $buffer) ; /* remove tabs, spaces, newlines, etc. */ $arr = array("\r\n", "\r", "\n", "\t", " ", " ", " ") ; $bu...

PHP在线压缩zip的函数代码

/* PHP创建zip压缩包 */function create_zip($files = array(),$destination = '',$overwrite = false) {//if the zip file already exists and overwrite is false, return falseif(file_exists($destination) && !$overwrite) { return false; }//vars$valid_files = array();//if files were passed in...if(is_array($files)) {//cycle through each fileforeach($files as $file) {//make sure the file existsif(file_exists...

php简单压缩英文字符串的代码

//replacement来自上个版本的加密替换 function compress_func($match) {return strlen($match[0]).$match[0]{0};} function uncompress_func($match) {return str_repeat($match[2], $match[1]);} function compress($str) { $i = 0; $pattern = array(); while(isset($replacement{$i})) array_push($pattern, "/".$replacement{$i++}."{2,}/"); return preg_replace_callback($pattern, "compress_func", ...

php实现图片压缩的二个例子【图】

/** * desription 压缩图片 * @param sting $imgsrc 图片路径 * @param string $imgdst 压缩后保存路径 */function image_png_size_add($imgsrc,$imgdst){ list($width,$height,$type)=getimagesize($imgsrc); $new_width = ($width>600?600:$width)*0.9; $new_height =($height>600?600:$height)*0.9; switch($type){ case 1: $giftype=check_gifcartoon($imgsrc); if($giftype){ header('Conten...

php压缩文件帮助类

/* File name: /include/zip.php Author: Horace 2009/04/15 */ class PHPZip{ var $dirInfo = array("0","0"); var $rootDir = ''; var $datasec = array(); var $ctrl_dir = array(); var $eof_ctrl_dir = "/x50/x4b/x05/x06/x00/x00/x00/x00"; var $old_offset = 0; function downloadZip(){ createZip($dir, $zipfilename, true); } functi...

PHP解压缩zip文件

可解压缩zip文件。它有两个参数:压缩文件的路径、目标文件的路径。 function unzip_file($file, $destination) { // create object $zip = new ZipArchive() ; // open archive if ($zip->open($file) !== TRUE) { die (Could not open archive); } // extract contents to destination directory $zip->extractTo($destination); // ...

PHP实现压缩html的函数

function compress_html($string) { $string = str_replace("\r\n", , $string); //清除换行符 $string = str_replace("\n", , $string); //清除换行符 $string = str_replace("\t", , $string); //清除制表符 $pattern = array ( "/> *([^ ]*) *</", //去掉注释标记 "/[\s]+/", "//", "/\" /", "/ \"/", ...

PHP实现zip压缩解压通用函数

function ezip($zip, $hedef = ){ $dirname=preg_replace(/.zip/, , $zip); $root = $_SERVER[DOCUMENT_ROOT]./zip/; // echo $root. $zip; $zip = zip_open($root . $zip); // var_dump($zip); @mkdir($root . $hedef . $dirname./.$zip_dosya); while($zip_icerik = zip_read($zip)){ $zip_dosya = zip_entry_name($zip_icerik); if(strpos($zip_dosya, .)){ $hedef_yol = $root ...

PHP压缩图片

function scale_dimensions_within_limits($w,$h,$max_w,$max_h){ // $w is the width of the current rectangle // $h is the height of the current rectangle // $max_w is the maximum width that an image can be sized // $max_h is the maximum height that an image can be sized // **** Heres where the magic is starts **** // Switch the concept of horiz/vertical/square to long/short side $short_s...

php启用gzip压缩加速网站

说明: 在服务器缓存了压缩过的文件,再次访问减少再压缩时间,降低CPU占用率。 通过设置客户端文件缓存时间,降低再次请求次数,可降低85%以上。 图片因为已经是压缩格式,只是设置客户端缓存时间,不做压缩处理。 使用方法: 服务器必须支持gzip,Rewrite功能。 在.htacess文件的“RewriteBase /”下面一行添加下面的代码 RewriteRule (..css$|..js$|..jpg$|..gif$|.*.png$) gzip.php?$1 上传gzip.php到根目录 4,在根...

PHP图片处理函数类(水印图,缩略图)[关于等比例压缩与裁剪压缩]

下面简单的写了一个图片处理类,功能包括:水印,缩略图等。不过,对于生成缩略图有两种方式:一种是直接按比例来压缩图片,另外一种是先裁剪再压缩的方式。在自己看来等例压缩与裁剪压缩区别就在于:等例压缩:能保证图片的宽长比例合理,且图片有完整性。但实际大小不保证符合要求。裁剪压缩: 能保证图片的宽长比例合理,实际大小也能保证。但图片完整性不能保证。 image.php <?php/** * * 图像处理类 * @author FC_LAMP * @int...

使用PHPZip解压缩文件

## PHPZip v1.2 by Sext (sext@neud.net) 2002-11-18# (Changed: 2003-03-01)## Makes zip archive## Based on "Zip file creation class", uses zLib##class PHPZip{function Zip($dir, $zipfilename){ if (@function_exists('gzcompress')) { $curdir = getcwd(); if (is_array($dir)) { $filelist = $dir; } else { $filelist =...

php压缩和解压缩字符串的代码

下面php代码通过gzcompress和gzuncompress压缩和解压缩字符串,可以设定压缩级别 $str = Hello I am a very very very very long string;$compressed = gzcompress($str, 9);//压缩级别为9$uncompressed = gzuncompress($compressed); echo $str, "\n";echo $uncompressed, "\n";echo base64_encode($compressed), "\n";echo bin2hex($compressed), "\n";echo urlencode($compressed), "\n"; php

php将文件压缩为zip文件

PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PHP ZIP 扩展已经开启。 /* 说明: 将多个文件压缩成一个zip文件的函数 * @param $files 数组类型 * @param destination 目标文件的路径 * @param $overwrite 是否为覆盖与目标文件相同的文件 */function create_zip($files = array(),$destination = '',$overwrite = false){ //如果zip文件已经存在并且设置为不重写返回fa...

php的zip压缩代码

$error = ""; //error holder if(isset($_POST['createpdf'])){ $post = $_POST; $file_folder = "files/"; // folder to load files if(extension_loaded('zip')){ // Checking ZIP extension is available if(isset($post['files']) and count($post['files']) > 0){ // Checking files are selected $zip = new ZipArchive(); // Load zip ...

HANDLER - 相关标签