Home > Backend Development > PHP Tutorial > Simple implementation of PHP merging multiple JS and CSS files based on incoming parameters_PHP tutorial

Simple implementation of PHP merging multiple JS and CSS files based on incoming parameters_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:28:18
Original
798 people have browsed it

HTML (how to use):

Copy code The code is as follows:



PHP:
Copy code The code is as follows:
//Output JS
header ("Content-type:application/x- javascript; Charset: utf-8");
if(isset($_GET)) {
$files = explode(",", $_GET['get']);
$str = ' ';
foreach ($files as $key => $val){
$str .= file_get_contents($_GET['path'].$val);
}

$str = str_replace("t", "", $str); //Clear spaces
$str = str_replace("rn", "", $str);
$str = str_replace( "n", "", $str);

// Delete single line comment
$str = preg_replace("///s*[a-zA-Z0-9_x7f-xff][a-zA-Z0-9_x7f-xff]*/", "" , $str);
// Delete multi-line comments
$str = preg_replace("//*[^/]**//s", "", $str);

echo $str;
}

//Output CSS
header ("content-type:text/css; charset: utf-8");
if(isset($_GET)) {
$files = explode(" ,", $_GET['get']);
$fc = '';
foreach ($files as $key => $val){
$fc .= file_get_contents($_GET[ 'path'].$val.".css");
}
$fc = str_replace("t", "", $fc); //Clear spaces
$fc = str_replace(" rn", "", $fc);
$fc = str_replace("n", "", $fc);
$fc = preg_replace("//*[^/]**//s ", "", $fc);
echo $fc;
}


is just a simple prototype without encapsulation. In addition, remember to cache the merged files.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/802226.htmlTechArticleHTML (how to use): Copy the code as follows: link rel="stylesheet" type="text/css" href="cssmin.php?get=base,style1,style2,globalv=20131023" / script type="text/javascript"...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template