PHP Implementation of CSS Update class instance, PHPCSS Update instance _php tutorial

Source: Internet
Author: User
Tags learn php learn php programming

PHP implementation of the CSS update class instance, PHPCSS Update instance


In this paper, we describe the CSS update class and its usage in PHP, which is very practical. Share to everyone for your reference. Specific as follows:

The CSSUpdate.class.php class file is as follows:

<?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_child 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 $replacetags need to replace Picture Type * @param boolean $search _child whether to traverse subfolders, false by default */Public function __construct ($csstmpl _path, $css _path, $repla Cetags=array (), $search _child=false) {if (!is_dir ($csstmpl _path) | |!is_dir ($css _path) | |! $replacetags) {$this-&     Gt;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 * @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 $this->traversing ($curf           ILE); }}elseif ($this->checkext ($curfile)) {//css file $dfile = str_replace ($this->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 target 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. "
"; }}?>

The Demo sample program is as follows:

<?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 ();?>

Full source Click here to download this site.

I hope this article will be helpful for you to learn PHP programming.


PHP changes the display content via CSS, the answer is 50 plus

I finished it with JavaScript.
============ first.html ===========



First.html</title>




</form>
</body>

============ second.html ==================



<title>Second.html</title></title>

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.