PHP CSS Update Class related content to explain

Source: Internet
Author: User
CSSUpdate.class.php

<?php/** CSS Update class, update the version of the image within the CSS file *date:2013-02-05*author:fdipzone*ver:1.1**func:*update (); * * ver:1.1 Add Search_chil    d parameter, 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 $replaceta The type of picture that the GS needs 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 o            R Csspath or replacetags error ');        Return ';        } $this->traversing ($this->csstmpl_path);    $this->response (' Covert num: '. $this->convert_num);         /** Traverse Folder * @param String $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 $th                    Is->traversing ($curfile); }}elseif ($this->checkext ($curfile)) {//css file $dfile = str_replace ($this->csst                    Mpl_path, $this->css_path, $curfile);           $this->create ($curfile, $dfile);         $this->response ($curfile. ' Convert to '. $dfile. ' Success ');                $this->convert_num + +;    }}} closedir ($handle);        }/** Check the 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 retur            n true;    }} return false; /** Replace template content, write Csspath * @param string $tmplfile template file * @param string $dfile destination file */Private function CR                Eate ($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

<?phprequire_once "CSSUpdate.class.php";d efine (' 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 ();? >

This article explains the PHP CSS Update class related content, more relevant content please pay attention to the PHP Chinese web.

Related recommendations:

About PHP __call and __callstatic content

About memcached common commands and instructions for use

About phpmailer-php e-mail Transport class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.