亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 開發 > CSS > 正文

php實現壓縮多個CSS與JS文件的方法

2020-03-22 17:32:24
字體:
來源:轉載
供稿:網友
本文實例講述了php實現壓縮多個CSS與JS文件的方法。分享給大家供大家參考。具體實現方法如下:1. 壓縮css復制代碼 代碼如下: php
header('Content-type: text/css');
ob_start("compress");
function compress($buffer) {
/* remove comments */
$buffer = preg_replace('!//*[^*]*/*+([^/][^*]*/*+)*/!', '', $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("/r/n", "/r", "/n", "/t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}

/* your css files */
include('galleria.css');
include('articles.css');

ob_end_flush();
使用方法如下:
復制代碼 代碼如下: link href="compress.php" rel="stylesheet" type="text/css" / span id="tester" test /span 2. 壓縮js,利用jsmin類:本實例源自:http://code.google.com/p/minify/
復制代碼 代碼如下:header('Content-type: text/javascript');
require 'jsmin.php';
echo JSMin::minify(file_get_contents('common.js') . file_get_contents('common2.js'));其中jsmin.php文件如下:復制代碼 代碼如下:
php
/**
* jsmin.php - PHP implementation of Douglas Crockford's JSMin.
*
* This is pretty much a direct port of jsmin.c to PHP with just a few
* PHP-specific performance tweaks. Also, whereas jsmin.c reads from stdin and
* outputs to stdout, this library accepts a string as input and returns another
* string as output.
*
* PHP 5 or higher is required.
*
* Permission is hereby granted to use this version of the library under the
* same terms as jsmin.c, which has the following license:
*
* --
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* The Software shall be used for Good, not Evil.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* --
*
* @package JSMin
* @author Ryan Grove ryan@wonko.com
* @copyright 2002 Douglas Crockford douglas@crockford.com (jsmin.c)
* @copyright 2008 Ryan Grove ryan@wonko.com (PHP port)
* @copyright 2012 Adam Goforth aag@adamgoforth.com (Updates)
* @license http://opensource.org/licenses/mit-license.php MIT License
* @version 1.1.2 (2012-05-01)
* @link http://github.com/rgrove/jsmin-php
*/
html' target='_blank'>class JSMin {
const ORD_LF = 10;
const ORD_SPACE = 32;
const ACTION_KEEP_A = 1;
const ACTION_DELETE_A = 2;
const ACTION_DELETE_A_B = 3;
protected $a = '';
protected $b = '';
protected $input = '';
protected $inputIndex = 0;
protected $inputLength = 0;
protected $lookAhead = null;
protected $output = '';
// -- Public Static Methods --------------------------------------------------
/**
* Minify Javascript
*
* @uses __construct()
* @uses min()
* @param string $js Javascript to be minified
* @return string
*/
public static function minify($js) {
$jsmin = new JSMin($js);
return $jsmin- min();
}
// -- Public Instance Methods ------------------------------------------------
/**
* Constructor
*
* @param string $input Javascript to be minified
*/
public function __construct($input) {
$this- input = str_replace("/r/n", "/n", $input);
$this- inputLength = strlen($this- input);
}
// -- Protected Instance Methods ---------------------------------------------
/**
* Action -- do something! What to do is determined by the $command argument.
*
* action treats a string as a single character. Wow!
* action recognizes a regular expression if it is preceded by ( or , or =.
*
* @uses next()
* @uses get()
* @throws JSMinException If parser errors are found:
* - Unterminated string literal
* - Unterminated regular expression set in regex literal
* - Unterminated regular expression literal
* @param int $command One of class constants:
* ACTION_KEEP_A Output A. Copy B to A. Get the next B.
* ACTION_DELETE_A Copy B to A. Get the next B. (Delete A).
* ACTION_DELETE_A_B Get the next B. (Delete B).
*/
protected function action($command) {
switch($command) {
case self::ACTION_KEEP_A:
$this- output .= $this-
case self::ACTION_DELETE_A:
$this- a = $this-
if ($this- a === "'" || $this- a === '"') {
for (;;) {
$this- output .= $this-
$this- a = $this- get();
if ($this- a === $this- b) {
break;
}
if (ord($this- a) = self::ORD_LF) {
throw new JSMinException('Unterminated string literal.');
}
if ($this- a === '//') {
$this- output .= $this-
$this- a = $this- get();
}
}
}
case self::ACTION_DELETE_A_B:
$this- b = $this- next();
if ($this- b === '/' && (
$this- a === '(' || $this- a === ',' || $this- a === '=' ||
$this- a === ':' || $this- a === '[' || $this- a === '!' ||
$this- a === '&' || $this- a === '|' || $this- a === ' ' ||
$this- a === '{' || $this- a === '}' || $this- a === ';' ||
$this- a === "/n" )) {
$this- output .= $this- a . $this-
for (;;) {
$this- a = $this- get();
if ($this- a === '[') {
/*
inside a regex [...] set, which MAY contain a '/' itself. Example: mootools Form.Validator near line 460:
return Form.Validator.getValidator('IsEmpty').test(element) || (/^( :[a-z0-9!#$%&'*+/= ^_`{|}~-]/. ){0,63}[a-z0-9!#$%&'*+/= ^_`{|}~-]@( :( :[a-z0-9]( :[a-z0-9-]{0,61}[a-z0-9]) /.)*[a-z0-9]( :[a-z0-9-]{0,61}[a-z0-9]) |/[( :( :25[0-5]|2[0-4][0-9]|[01] [0-9][0-9] )/.){3}( :25[0-5]|2[0-4][0-9]|[01] [0-9][0-9] )/])$/i).test(element.get('value'));
*/
for (;;) {
$this- output .= $this-
$this- a = $this- get();
if ($this- a === ']') {
break;
} elseif ($this- a === '//') {
$this- output .= $this-
$this- a = $this- get();
} elseif (ord($this- a) = self::ORD_LF) {
throw new JSMinException('Unterminated regular expression set in regex literal.');
}
}
} elseif ($this- a === '/') {
break;
} elseif ($this- a === '//') {
$this- output .= $this-
$this- a = $this- get();
} elseif (ord($this- a) = self::ORD_LF) {
throw new JSMinException('Unterminated regular expression literal.');
}
$this- output .= $this-
}
$this- b = $this- next();
}
}
}
/**
* Get next char. Convert ctrl char to space.
*
* @return string|null
*/
protected function get() {
$c = $this- lookAhead;
$this- lookAhead = null;
if ($c === null) {
if ($this- inputIndex $this- inputLength) {
$c = substr($this- input, $this- inputIndex, 1);
$this- inputIndex += 1;
} else {
$c = null;
}
}
if ($c === "/r") {
return "/n";
}
if ($c === null || $c === "/n" || ord($c) = self::ORD_SPACE) {
return $c;
}
return ' ';
}
/**
* Is $c a letter, digit, underscore, dollar sign, or non-ASCII character.
*
* @return bool
*/
protected function isAlphaNum($c) {
return ord($c) 126 || $c === '//' || preg_match('/^[/w/$]$/', $c) === 1;
}
/**
* Perform minification, return result
*
* @uses action()
* @uses isAlphaNum()
* @uses get()
* @uses peek()
* @return string
*/
protected function min() {
if (0 == strncmp($this- peek(), "/xef", 1)) {
$this- get();
$this- get();
$this- get();
}
$this- a = "/n";
$this- action(self::ACTION_DELETE_A_B);
while ($this- a !== null) {
switch ($this- a) {
case ' ':
if ($this- isAlphaNum($this- b)) {
$this- action(self::ACTION_KEEP_A);
} else {
$this- action(self::ACTION_DELETE_A);
}
break;
case "/n":
switch ($this- b) {
case '{':
case '[':
case '(':
case '+':
case '-':
case '!':
case '~':
$this- action(self::ACTION_KEEP_A);
break;
case ' ':
$this- action(self::ACTION_DELETE_A_B);
break;
default:
if ($this- isAlphaNum($this- b)) {
$this- action(self::ACTION_KEEP_A);
}
else {
$this- action(self::ACTION_DELETE_A);
}
}
break;
default:
switch ($this- b) {
case ' ':
if ($this- isAlphaNum($this- a)) {
$this- action(self::ACTION_KEEP_A);
break;
}
$this- action(self::ACTION_DELETE_A_B);
break;
case "/n":
switch ($this- a) {
case '}':
case ']':
case ')':
case '+':
case '-':
case '"':
case "'":
$this- action(self::ACTION_KEEP_A);
break;
default:
if ($this- isAlphaNum($this- a)) {
$this- action(self::ACTION_KEEP_A);
}
else {
$this- action(self::ACTION_DELETE_A_B);
}
}
break;
default:
$this- action(self::ACTION_KEEP_A);
break;
}
}
}
return $this- output;
}
/**
* Get the next character, skipping over comments. peek() is used to see
* if a '/' is followed by a '/' or '*'.
*
* @uses get()
* @uses peek()
* @throws JSMinException On unterminated comment.
* @return string
*/
protected function next() {
$c = $this- get();
if ($c === '/') {
switch($this- peek()) {
case '/':
for (;;) {
$c = $this- get();
if (ord($c) = self::ORD_LF) {
return $c;
}
}
case '*':
$this- get();
for (;;) {
switch($this- get()) {
case '*':
if ($this- peek() === '/') {
$this- get();
return ' ';
}
break;
case null:
throw new JSMinException('Unterminated comment.');
}
}
default:
return $c;
}
}
return $c;
}
/**
* Get next char. If is ctrl character, translate to a space or newline.
*
* @uses get()
* @return string|null
*/
protected function peek() {
$this- lookAhead = $this- get();
return $this- lookAhead;
}
}
// -- Exceptions ---------------------------------------------------------------
class JSMinException extends Exception {}

希望本文所述對大家的php程序設計有所幫助。PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美美女18p| 136fldh精品导航福利| 欧美激情18p| 国产精品人成电影| 亚洲美腿欧美激情另类| 亚洲国产小视频在线观看| 国产精品久久久久av免费| 欧美激情xxxx性bbbb| 国产亚洲欧美视频| 日韩电视剧在线观看免费网站| 成人亚洲综合色就1024| 中文综合在线观看| 国产日韩精品在线播放| 性金发美女69hd大尺寸| 欧美韩日一区二区| 最近的2019中文字幕免费一页| 久久精品国产91精品亚洲| 久久精品国产一区二区电影| 日韩精品丝袜在线| 国产精品丝袜久久久久久高清| 国产精品露脸av在线| 国产精品一区久久久| 欲色天天网综合久久| 亚洲欧美资源在线| 国产九九精品视频| 国产精品专区h在线观看| 亚洲在线免费看| 久久精品这里热有精品| 国产在线日韩在线| 亚洲美腿欧美激情另类| 国模gogo一区二区大胆私拍| 福利一区视频在线观看| 情事1991在线| 亚洲а∨天堂久久精品9966| 91午夜理伦私人影院| 欧美成人精品xxx| 久久精品色欧美aⅴ一区二区| 国产一区二区日韩精品欧美精品| 日本久久久久久| 在线观看欧美视频| 97在线视频一区| 国产精品第一页在线| 亚洲国产免费av| 国产99久久精品一区二区| 蜜臀久久99精品久久久无需会员| 国产成人综合一区二区三区| 欧美性生交大片免网| 不卡在线观看电视剧完整版| 俺去了亚洲欧美日韩| 日韩精品免费观看| 亚洲欧美中文另类| 国产精品一二区| 日韩欧美国产视频| 97精品免费视频| 国产精品视频网| 国产美女久久精品香蕉69| 亚洲aⅴ日韩av电影在线观看| 久久全球大尺度高清视频| 日韩av电影在线网| 成人a级免费视频| 亚洲国产精品成人一区二区| 国产精品永久免费| 日本一欧美一欧美一亚洲视频| 日韩在线免费高清视频| 欧美国产日韩一区二区在线观看| 亚洲欧美在线一区二区| 欧美日韩国产一中文字不卡| 久久久91精品| 国产99在线|中文| 亚洲无亚洲人成网站77777| 91中文字幕在线观看| 黑人巨大精品欧美一区免费视频| 国产精品美乳一区二区免费| 91在线免费看网站| 久久免费少妇高潮久久精品99| 国产精品一区二区三区免费视频| 国产精品黄视频| 久久久999精品视频| 久久伊人91精品综合网站| 国内外成人免费激情在线视频| 成人国产亚洲精品a区天堂华泰| 国产激情999| 久久久999精品免费| 成人字幕网zmw| 久久视频免费在线播放| 在线观看国产精品91| 亚洲成人久久一区| 亚洲综合国产精品| 日韩亚洲一区二区| 亚洲男人av在线| 国产精品久久久久91| 亚洲福利在线播放| 在线成人免费网站| 欧美性高潮在线| 欧美另类老肥妇| 成人免费高清完整版在线观看| 国产精品久久久久久久9999| 国产97人人超碰caoprom| 亚洲精品成人av| 欧美精品做受xxx性少妇| 狠狠色狠色综合曰曰| 色婷婷**av毛片一区| 午夜精品国产精品大乳美女| 国产区精品在线观看| 欧美亚洲成人免费| 精品性高朝久久久久久久| 亚洲xxxx在线| 在线播放亚洲激情| 亚洲人成五月天| www.久久久久| 亚洲在线视频福利| 国产美女久久精品香蕉69| 成人h片在线播放免费网站| 欧美性开放视频| 另类专区欧美制服同性| 91免费综合在线| 青青草成人在线| 日韩av综合中文字幕| 亚洲精品v欧美精品v日韩精品| 国产精品久久久久久超碰| 欧美性猛交xxxx偷拍洗澡| 亚洲电影中文字幕| 久久99国产综合精品女同| 欧美一乱一性一交一视频| 欧美日韩亚洲一区二| 国产精品久久久久久婷婷天堂| 成人夜晚看av| 日韩成人av在线播放| 久久久久久高潮国产精品视| 久久免费国产精品1| 奇门遁甲1982国语版免费观看高清| 一本色道久久综合亚洲精品小说| 日本伊人精品一区二区三区介绍| 欧美精品在线观看91| 欧美整片在线观看| 国产suv精品一区二区三区88区| 久久久精品2019中文字幕神马| 久久精品免费电影| 亚洲毛片在线看| 中文字幕久久久av一区| 亚洲欧美制服另类日韩| 精品露脸国产偷人在视频| 久久视频国产精品免费视频在线| 亚洲美女视频网站| 欧美在线一级va免费观看| 欧美xxxx做受欧美| 午夜精品久久久久久久男人的天堂| 91精品国产高清自在线看超| 国产精品电影网站| 国产精品一区久久久| 亚洲天天在线日亚洲洲精| 日本精品视频网站| 欧美成人一二三| 欧美日韩亚洲系列| 国产精品视频播放| 国产精品国产三级国产专播精品人| 中文精品99久久国产香蕉| 国产精品久久久久久久久久| 黑人巨大精品欧美一区二区三区| 成人a视频在线观看| 日本一区二区三区在线播放| 国产精品视频中文字幕91| 久热国产精品视频| 69精品小视频|