·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> php js css加载合并函数 宋正河整理

php js css加载合并函数 宋正河整理

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
php js CSS加载合并函数 宋正河整理
<?php//phpjscss加载合并函数宋正河整理//转载请注明出处define('COMBINE_JS',true);define('COMBINE_CSS',true);define('application_JS_ROOT','E:/wwwroot/m/js/');define('APPLICATION_CSS_ROOT','E:/wwwroot/m/css/');define('SC_ROOT','E:/wwwroot/m/static_cache/');define('SC_URL','http://www.localhost.com/m/static_cache/');define('APPLICATION_JS','http://www.localhost.com/m/js/');define('APPLICATION_CSS','http://www.localhost.com/m/css/');functionload_combine_js($js,$path=array(),$origin=false,$part=1){if(!is_array($js))returnfalse;if(empty($path)){$path_url=APPLICATION_JS;$path_root=APPLICATION_JS_ROOT;}if($originor(!COMBINE_JS)){$string='';for($i=0;$i<count($js);$i++){$string.="<scriptsrc='{$path_url}{$js[$i]}.js'></script>\n";}echo$string;returntrue;}$cache_filename='js-'.md5($_SERVER['SCRIPT_NAME'].$part).'.js';if(!file_exists(SC_ROOT.$cache_filename)){$file_content='';for($i=0;$i<count($js);$i++){$f=$path_root.$js[$i].'.js';if(file_exists($f))$file_content.=file_get_contents($f)."\n";}file_put_contents(SC_ROOT.$cache_filename,$file_content);}$file=SC_URL.$cache_filename;echo"<scriptsrc='{$file}'></script>\n";returntrue;}functionload_combine_css($css,$path=array(),$origin=false,$part=1){if(!is_array($css))returnfalse;if(empty($path)){$path_url=APPLICATION_CSS;$path_root=APPLICATION_CSS_ROOT;}if($originor(!COMBINE_CSS)){$string='';for($i=0;$i<count($css);$i++){$string.="<linkhref='{$path_url}{$css[$i]}.css'rel='stylesheet'type='text/css'/>\n";}echo$string;returntrue;}$cache_filename='css-'.md5($_SERVER['SCRIPT_NAME'].$part).'.css';if(!file_exists(SC_ROOT.$cache_filename)){$file_content='';for($i=0;$i<count($css);$i++){$f=$path_root.$css[$i].'.css';if(file_exists($f))$file_content.=file_get_contents($f)."\n";}file_put_contents(SC_ROOT.$cache_filename,$file_content);}$file=SC_URL.$cache_filename;echo$string="<linkhref='{$file}'rel='stylesheet'type='text/css'/>\n";returntrue;}?><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title>无标题文档</title><?phpload_combine_js(array('a','b'),array(),true);load_combine_js(array('a','b'));load_combine_css(array('1','2'),array(),true);load_combine_css(array('1','2'));?></head><body>123</body></html>