午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    php實(shí)現(xiàn)的CSS更新類實(shí)例
    來源:易賢網(wǎng) 閱讀:699 次 日期:2014-10-11 10:05:35
    溫馨提示:易賢網(wǎng)小編為您整理了“php實(shí)現(xiàn)的CSS更新類實(shí)例”,方便廣大網(wǎng)友查閱!

    CSSUpdate.class.php類文件如下:

    <?php

    /** css 更新類,更新css文件內(nèi)圖片的版本

    * Date: 2013-02-05

    * Author: fdipzone

    * Ver: 1.1

    *

    * Func:

    * update();

    *

    * Ver: 1.1 增加search_child參數(shù),可遍歷子文件夾

    */

    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;

    /** 初始化

    * @param String $csstmpl_path css模版路徑

    * @param String $css_path css目標(biāo)路徑

    * @param Array $replacetags 需要替換的圖片類型

    * @param boolean $search_child 是否遍歷子文件夾,默認(rèn)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;

    }

    }

    /** 更新css文件 */

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

    }

    /** 遍歷文件夾

    * @param String $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){ // 需要遍歷子文件夾

    $this->traversing($curfile);

    }

    }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);

    }

    /** 檢查文件后綴 */

    private function checkExt($file){

    $name = basename($file);

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

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

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

    return true;

    }

    }

    return false;

    }

    /** 替換模版內(nèi)容,寫入csspath

    * @param String $tmplfile 模版文件

    * @param String $dfile 目標(biāo)文件

    */

    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))){ // 生成目標(biāo)路徑

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

    }

    file_put_contents($dfile, $css_content, true);

    }

    /** 輸出 */

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

    ?>

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:php實(shí)現(xiàn)的CSS更新類實(shí)例
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)