CSSUpdate.class.php
<?php/** CSS Update class, update the version of the picture in the CSS file * date:2013-02-05 * author:fdipzone * ver:1.1 * * Func: * up
Date ();
* * ver:1.1 Add search_child parameters, can traverse subfolder/class cssupdate{private $csstmpl _path = null;
Private $CSS _path = null;
Private $replacetags = Array ();
Private $search _child = false;
Private $convert _num = 0;
Private $is _ready = 0; /** Initialize * @param string $csstmpl _path css Template path * @param String $css _path CSS Target path * @param Array $rep Lacetags the type of picture you want to replace * @param boolean $search _child whether to traverse subfolders, default false/Public function __construct ($csstmpl _ Path, $css _path, $replacetags =array (), $search _child=false) {if (!is_dir ($csstmpl _path) | |!is_dir ($css _path) | |
! $replacetags) {$this->is_ready = 0;
}else{$this->csstmpl_path = $csstmpl _path;
$this->css_path = $css _path; $this->replacetags= $replacetags;
$this->search_child = $search _child;
$this->is_ready = 1;
}/** Update CSS file */Public Function update () {if ($this->is_ready==0) {
$this->response (' Csstmpl or Csspath or replacetags error ');
Return ";
$this->traversing ($this->csstmpl_path);
$this->response (' Covert num: '. $this->convert_num); /** Traverse Folder * View this column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/* @param strin
G $path File path */Private function traversing ($path) {$handle = Opendir ($path); while (($file =readdir ($handle))!==false) {if ($file!= ' ... ' && $file!= '. ') {$curfile = $path. '
/'. $file;
if (Is_dir ($curfile)) {//folder if ($this->search_child) {//need to traverse subfolders $this->traversing ($curfile); }}elseif ($this->checkext ($curfile)) {//css file $dfile = str_replace ($this-&G
T;csstmpl_path, $this->css_path, $curfile);
$this->create ($curfile, $dfile);
$this->response ($curfile. ' Convert to '. $dfile. ' Success ');
$this->convert_num + +;
}} closedir ($handle);
/** Check file suffix * * Private function Checkext ($file) {$name = basename ($file);
$namefrag = Explode ('. ', $name);
if (count ($namefrag) >=2) {if Strtolower ($namefrag [Count ($namefrag) 1]) = = ' css ') {//CSS file
return true;
return false; /** Replace template content, write Csspath * @param string $tmplfile template file * @param string $dfile MeshStandard file/Private function Create ($tmplfile, $dfile) {$css _content = file_get_contents ($tmplfile); foreach ($this->replacetags as $tag) {$css _content = Str_replace ($tag, $tag. "?".
Date (' Ymdhis '), $css _content);
} if (!is_dir (DirName ($dfile)) {//Generate target path mkdir (dirname ($dfile), 0755, true);
} file_put_contents ($dfile, $css _content, True); /** Output */Private Function response ($content) {echo $content. "
<br> "; }}?>
Demo
<?php
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 = new Cssupdate ($csstmpl _path, $css _path, $replacetags);
$cssobj->update ();
? >
SOURCE Download Address: http://download.csdn.net/detail/fdipzone/5786377
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/