首頁 > 後端開發 > php教程 > php js css加载合并函数 宋正河整理,css宋正河_PHP教程

php js css加载合并函数 宋正河整理,css宋正河_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-07-13 09:50:26
原創
1064 人瀏覽過

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

<?php

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

//转载请注明出处

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/');

  

function load_combine_js($js,$path=array(),$origin=false,$part=1){

    if(!is_array($js)) return false;

    if(empty($path)){

        $path_url=APPLICATION_JS;

        $path_root=APPLICATION_JS_ROOT;

    }

    if($origin or (!COMBINE_JS)){

        $string='';

        for($i=0;$i<count($js);$i++){$string.="<script src='{$path_url}{$js[$i]}.js'></script>\n";}

        echo $string;

        return true;

    }

    $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 "<script src='{$file}'></script>\n";

    return true;

}

  

function load_combine_css($css,$path=array(),$origin=false,$part=1){

    if(!is_array($css)) return false;

    if(empty($path)){

        $path_url=APPLICATION_CSS;

        $path_root=APPLICATION_CSS_ROOT;

    }

    if($origin or (!COMBINE_CSS)){

        $string='';

        for($i=0;$i<count($css);$i++){$string.="<link href='{$path_url}{$css[$i]}.css' rel='stylesheet' type='text/css' />\n";}

        echo $string;

        return true;

    }

    $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="<link href='{$file}' rel='stylesheet' type='text/css' />\n";

    return true;

}

  

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<?php

load_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>

登入後複製

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1017650.htmlTechArticlephp js css加载合并函数 宋正河整理,css宋正河 ?php//phpjscss加载合并函数宋正河整理//转载请注明出处define('COMBINE_JS',true);define('COMBINE_CSS',tru...
相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
怎麼學好php
來自於 1970-01-01 08:00:00
0
0
0
PHP擴充intl
來自於 1970-01-01 08:00:00
0
0
0
php數據獲取?
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板