当前位置:Gxlcms > PHP教程 > php实现的CSS更新类实例,phpcss更新实例_PHP教程

php实现的CSS更新类实例,phpcss更新实例_PHP教程

时间:2021-07-01 10:21:17 帮助过:5人阅读

php实现的CSS更新类实例,phpcss更新实例


本文实例讲述了php实现的CSS更新类及其用法,非常实用。分享给大家供大家参考。具体如下:

CSSUpdate.class.php类文件如下:

<?php 
/** css 更新类,更新css文件内图片的版本 
*  Date:  2013-02-05 
*  Author: fdipzone 
*  Ver:  1.1 
* 
*  Func: 
*  update(); 
* 
*  Ver:  1.1 增加search_child参数,可遍历子文件夹 
*/ 
 
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目标路径 
  * @param Array  $replacetags 需要替换的图片类型 
  * @param boolean $search_child 是否遍历子文件夹,默认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; 
  } 
 
  /** 替换模版内容,写入csspath 
  * @param String $tmplfile 模版文件 
  * @param String $dfile  目标文件 
  */ 
  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))){  // 生成目标路径 
      mkdir(dirname($dfile), 0755, true); 
    } 
    file_put_contents($dfile, $css_content, true); 
  } 
 
  /** 
输出 */ private function response($content){ echo $content."
"; } } ?>

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

完整源码点击此处本站下载。

希望本文所述对大家PHP程序设计的学习有所帮助。


PHP通过css改变显示内容,答案正确另加50

我用javascript完成的
============ first.html ===========



first.html</title><br /></head><br /><body><br /><form action="second.html" method="get" name="myform"><br /> <input name="csstype" type="text" /><br /> <input name="submit" type="submit" /><br /></form><br /></body><br /></html><br /><br />============ second.html ==================<br /><br /><html><br /><head><br /><title>second.html</title><br /><style type="text/css"><br />.type1 h1 {<br /> color:#f00;<br />}<br />.type1 p {<br /> color:#0f0;<br />}<br />.type2 h1 {<br /> color:#ffff00;<br />}<br />.type2 p {<br /> color:#00ffff;<br />}<br />.type3 h1 {<br /> color:#ff00ff;<br />}<br />.type3 p {<br /> color:#ff00ff;<br />}<br /></style><br /></head><br /><body><br /><br /> <script type="text/javascript" language="javascript"><br />function QueryString(item){<br /> var sValue=location.search.match(new RegExp("[\?\&]"+item+"=([^\&]*)(\&?)","i"))<br /> return sValue?sValue[1]:sValue<br />}<br />var csstype=QueryString('csstype');<br />var wrap=document.getElementById("wrap")<br />switch(csstype)<br />{<br /> case "2":<br /> wrap.className="type2";<br /> break;<br /> case "3":<br /> wrap.className="type3";<br /> break;<br /> default:<br /> wrap.className="type1";<br />}<br /></script><br /> <h2>标题</h1><br /> <p>正文正文正文<......余下全文>><br/>  </br> <span class="icon i-relatedanswer"><h3>php 怎可以动态获取css里面的数据,例如:动态的改变宽度与高度</h3></span> <p class="ft p1">这个应该是在html页面需要用javascript来获取的啊,你服务器语言怎么去获取人家浏览器里运行的html页面的css。<br /></div><br /><script type="text/javascript"><br />document.write(document.getElementById( "#test" ).style.backgroundColor);<br /></script><br />应该是像这样获取的,如果你服务器硬是需要这些信息,就用ajax或者表单再传回给服务器的php页面<br/>  </br></p> <p align="left"><span id="url" itemprop="url">http://www.bkjia.com/PHPjc/882902.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/882902.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">php实现的CSS更新类实例,phpcss更新实例 本文实例讲述了php实现的CSS更新类及其用法,非常实用。分享给大家供大家参考。具体如下: CSSU...</span></p> </div> <div class=""> <ul class="m-news-opt fix"> <li class="opt-item"> <a href='/PHPjiqiao-156186.html' target='_blank'><p>< 上一篇</p><p class="ellipsis">php中unserialize返回false的解决方法_PHP教程</p></a> </li> <li class="opt-item ta-r"> <a href='/PHPjiqiao-156188.html' target='_blank'><p>下一篇 ></p><p class="ellipsis">php中json_encodeUTF-8中文乱码问题,_PHP教程</p></a> </li> </ul> </div> </div> </div> <div class="g-title fix"> <h2 class="title-txt">人气教程排行</h2> </div> <div class="m-rank u-dashed mb40"> <ul> <li class="rank-item"> <a href="/PHPjiqiao-379253.html" title='php如何获取跳转前的url' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num top">1</span> php如何获取跳转前的url </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-379019.html" title='php格林威治时间转换成当前时间的方法' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num second">2</span> php格林威治时间转换成当前时间的方法 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-366629.html" title='为什么php不能做大型系统?' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num third">3</span> 为什么php不能做大型系统? </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-207623.html" title='range函数怎么用' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">4</span> range函数怎么用 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-162433.html" title='php中计算页面加载时间几种方法总结_PHP教程' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">5</span> php中计算页面加载时间几种方法总结_PHP教程 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-140221.html" title='求帮助,关于paypal支付返回值修改订单状态' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">6</span> 求帮助,关于paypal支付返回值修改订单状态 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-103588.html" title='typecho怎么配置文章内容页?' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">7</span> typecho怎么配置文章内容页? </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-99213.html" title='PhpStorm左侧structure不显示文件的方法列表是这么回事?' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">8</span> PhpStorm左侧structure不显示文件的方法列表是这么回事? </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-92208.html" title='查看PHP的环境变量_PHP' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">9</span> 查看PHP的环境变量_PHP </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-170.html" title='PHP Primary script unknown 解决方法总结' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">10</span> PHP Primary script unknown 解决方法总结 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-148.html" title='php的命名空间与自动加载实现方法' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">11</span> php的命名空间与自动加载实现方法 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-133.html" title='解决laravel 出现ajax请求419(unknown status)的问题' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">174次</span> <span class="g-sort-num ">12</span> 解决laravel 出现ajax请求419(unknown status)的问题 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-462817.html" title='php 如何删除mysql记录' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">173次</span> <span class="g-sort-num ">13</span> php 如何删除mysql记录 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-388448.html" title='PHP如何替换数组中的指定元素' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">173次</span> <span class="g-sort-num ">14</span> PHP如何替换数组中的指定元素 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-124270.html" title='怎么去除字符串中非汉字、非字母、非数字的字符' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">173次</span> <span class="g-sort-num ">15</span> 怎么去除字符串中非汉字、非字母、非数字的字符 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-112291.html" title='mysql如何一次执行多条SQL语句' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">173次</span> <span class="g-sort-num ">16</span> mysql如何一次执行多条SQL语句 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-110669.html" title='修改header里面的Connection为close解决方法' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">173次</span> <span class="g-sort-num ">17</span> 修改header里面的Connection为close解决方法 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-153.html" title='PHP基于session.upload_progress 实现文件上传进度显示功能详解' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">173次</span> <span class="g-sort-num ">18</span> PHP基于session.upload_progress 实现文件上传进度显示功能详解 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-125.html" title='php5.6.x到php7.0.x特性小结' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">173次</span> <span class="g-sort-num ">19</span> php5.6.x到php7.0.x特性小结 </a> </li> <li class="rank-item"> <a href="/PHPjiqiao-378118.html" title='php为什么会出现504错误' class="item-name ellipsis" target="_blank"> <span class="g-art-count fr">172次</span> <span class="g-sort-num ">20</span> php为什么会出现504错误 </a> </li> </ul> </div> </div> </div> <!-- / 教程内容页 --> </div> </div> <!-- 页尾 --> <div class="footer"> 本站所有资源全部来源于网络,若本站发布的内容侵害到您的隐私或者利益,请联系我们删除!</div> <!-- / 页尾 --> <script type="text/javascript" src="/kan/js/read.js"></script> <div style="display:none"> <div class="login-box" id="login-dialog"> <div class="login-top"><a class="current" rel="nofollow" id="login1" onclick="setTab('login',1,2);" >登录</a></div> <div class="login-form" id="nav-signin"> <!-- <div class="login-ico"><a rel="nofollow" class="qq" id="qqlogin" target="_blank" href="/user-center-qqlogin.html"> QQ </a></div> --> <div class="login-box-form" id="con_login_1"> <form id="loginform" action="/user-center-login.html" method="post" onsubmit="return false;"> <p class="int-text"> <input class="email" id="username" name="username" type="text" value="用户名或Email" onfocus="if(this.value=='用户名或Email'){this.value='';}" onblur="if(this.value==''){this.value='用户名或Email';};" ></p> <p class="int-text"> <input class="password1" type="password" id="password" name="password" value="******" onBlur="if(this.value=='') this.value='******';" onFocus="if(this.value=='******') this.value='';" > </p> <p class="int-info"> <label class="ui-label"> </label> <label for="agreement" class="ui-label-checkbox"> <input type="checkbox" value="" name="cookietime" id="cookietime" checked="checked" value="2592000"> <input type="hidden" name="notforward" id="notforward" value="1"> <input type="hidden" name="dosubmit" id="dosubmit" value="1">记住我的登录 </label> <a rel="nofollow" class="aright" href="/user-center-forgetpwd.html" target="_blank"> 忘记密码? </a></p> <p class="int-btn"><a rel="nofollow" id="loginbt" class="loginbtn"><span>登录</span></a></p> </form> </div> <form id="regform" action="/user-center-reg.html" method="post"> <div class="login-reg" style="display: none;" id="con_login_2"> <input type="hidden" name="t" id="t"/> <p class="int-text"> <input id="email" name="email" type="text" value="Email" onfocus="if(this.value=='Email'){this.value='';}" onblur="if(this.value==''){this.value='Email';};"></p> <p class="int-text"> <input id="uname" name="username" type="text" value="用户名或昵称" onfocus="if(this.value=='用户名或昵称'){this.value='';}" onblur="if(this.value==''){this.value='用户名或昵称';};"></p> <p class="int-text"> <input type="password" id="pwd" name="password" value="******" onBlur="if(this.value=='') this.value='******';" onFocus="if(this.value=='******') this.value='';"> </p> <p class="int-text1"><span class="inputbox"> <input id="validate" name="validate" type="text" value="验证码" onfocus="if(this.value=='验证码'){this.value='';}" onblur="if(this.value==''){this.value='验证码';};"> </span><span class="yzm-img"><img src="/user-checkcode-index" alt="看不清楚换一张" id="indexlogin"></p> <p class="int-info"> <label> <input value="" name="agreement" id="agreement" CHECKED="checked" type="checkbox"> 我已阅读<a rel="nofollow" href="/user-center-agreement.html">用户协议</a>及<a rel="nofollow" href="/user-center-agreement.html">版权声明</a></label> </p> <p class="int-btn"><input type="hidden" name="dosubmit"/> <a rel="nofollow" class="loginbtn" id="register"><span>注册</span></a></p> </div> </form> </div> </div> </div> </div> <script type="text/javascript" src="/kan/js/foot_js.js"></script> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?6dc1c3c5281cf70f49bc0bc860ec24f2"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script type="text/javascript" src="/layui/layui.js"></script> <script> layui.use('code', function() { layui.code({ elem: 'pre', //默认值为.layui-code about: false, skin: 'notepad', title: 'php怎么实现数据库验证跳转代码块', encode: true //是否转义html标签。默认不开启 }); }); </script> </body> </html>