php_PHP チュートリアルに実装された CSS 更新クラスの例

WBOY
リリース: 2016-07-13 10:18:41
オリジナル
866 人が閲覧しました

phpで実装されたCSS更新クラスの例

CSSUpdate.class.phpクラスファイルは以下のとおりです:

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

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

/**css update クラス、CSS ファイル内の画像のバージョンを更新します

* 日付: 2013-02-05

* 著者: fdipzone

* バージョン: 1.1

*

* 機能:

* 更新()

*

* Ver: 1.1 サブフォルダーをトラバースするための search_child パラメーターを追加します

*/

クラス CSSUpdate{

プライベート$csstmpl_path = null;

プライベート$css_path = null;

プライベート $replacetags = array();

プライベート $search_child = false

プライベート $convert_num = 0;

プライベート $is_ready = 0;

/**初期化

* @param String $csstmpl_path CSS テンプレートのパス

* @param String $css_path CSS ターゲット パス

* @param Array $replacetags 置換される画像のタイプ

* @param boolean $search_child サブフォルダーをトラバースするかどうか、デフォルトは false

*/

パブリック関数 __construct($csstmpl_path, $css_path, $replacetags=array(), $search_child=false){

if(!is_dir($csstmpl_path) || !is_dir($css_path) || !$replacetags){

$this->is_ready = 0;

}その他{

$this->csstmpl_path = $csstmpl_path;

$this->css_path = $css_path;

$this->replacetags = $replacetags;

$this->search_child = $search_child;

$this->is_ready = 1; 

}

}

/**CSSファイルを更新する*/

パブリック関数 update(){

if($this->is_ready==0){

$this->response('csstmpl または csspath または replacetags エラー'); 

「」を返します。 

}

$this->traversing($this->csstmpl_path); 

$this->response('covert num:'.$this->convert_num); 

}

/**フォルダーをトラバースする

* @param String $path ファイルパス

*/

プライベート関数のトラバース($path){

$handle = opendir($path); 

while(($file=readdir($handle))!==false){

if($file!='..' && $file!='.'){

$curfile = $path.'/'.$file; 

if(is_dir($curfile)){ // フォルダー

if($this->search_child){ // 必要遍历子文件夹

$this->traversing($curfile); 

}

}elseif($this->checkExt($curfile)){ // css ファイル

$dfile = str_replace($this->csstmpl_path, $this->css_path, $curfile); 

$this->create($curfile, $dfile); 

$this->response($curfile.' '.$dfile.' に変換成功'); 

$this->convert_num ++; 

}

}

}

closedir($handle); 

}

/**ファイルの拡張子をチェックする*/

プライベート関数 checkExt($file){

$name = ベース名($file); 

$namefrag =explode('.', $name); 

if(count($namefrag)>=2){

if(strto lower($namefrag[count($namefrag)-1])=='css'){ // css文件

true を返します。 

}

}

false を返します。 

}

/**テンプレートのコンテンツを置き換えて csspath に書き込みます

* @param String $tmplfile テンプレート ファイル

* @param String $dfile 対象ファイル

*/

プライベート関数 create($tmplfile, $dfile){

$css_content = file_get_contents($tmplfile); 

foreach($this->タグを $tag に置き換える){

$css_content = str_replace($tag, $tag."?".date('YmdHis'), $css_content); 

}

if(!is_dir(dirname($dfile))){ // 生成目标路径

mkdir(dirname($dfile), 0755, true); 

}

file_put_contents($dfile, $css_content, true); 

}

/**出力*/

プライベート関数の応答($content){

echo $content."
"; 

}

}

?>

デモ例手順序以下:

1

2

3

4

5

6

7

8

9

10

11

require_once "CSSUpdate.class.php"; 

define('ROOT_PATH', dirname(__FILE__)); 

$css_path = ROOT_PATH.'/css'; 

$csstmpl_path = ROOT_PATH.'/csstmpl'; 

$replacetags = array('.png', '.jpg', '.gif'); 

$cssobj = 新しい CSSUpdate($csstmpl_path, $css_path, $replacetags); 

$cssobj->update(); 

?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/882705.html技術記事 php の CSS 更新例 CSSUpdate.class.php 文例以下: 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 3 34 35 36 37 38 39 40...
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!