栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

PHP根据传入参数合并多个JS和CSS文件的简单实现

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PHP根据传入参数合并多个JS和CSS文件的简单实现

HTML(使用方法):
复制代码 代码如下:


PHP:
复制代码 代码如下://输出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); //清除空格
 $str = str_replace("rn", "", $str);
 $str = str_replace("n", "", $str);

 // 删除单行注释
 $str = preg_replace("///s*[a-zA-Z0-9_x7f-xff][a-zA-Z0-9_x7f-xff]*/", "", $str);
 // 删除多行注释
 $str = preg_replace("//s", "", $str);

 echo $str;
}

//输出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); //清除空格
 $fc = str_replace("rn", "", $fc);
 $fc = str_replace("n", "", $fc);
 $fc = preg_replace("//s", "", $fc);
 echo $fc;
}
只是个简单原型,没有封装。另外,合并后的文件记得配合缓存。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/48052.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号