zoukankan      html  css  js  c++  java
  • 一段小代码,发布网页时为js 、css 文件加上版本号

    <?php
    
     function addver($str,$version){ // $str: html file codes
             $head = '/\<head\>.*\<\/head\>/is';
            $search = '/\.css\\s*(?=["\'])/i';        
            $replace = '.css?v='.$version;        
            $search_js = '/\.js\\s*(?=["\'])/i';
            $replace_js = '.js?v='.$version;  
            
            preg_match($head ,$str,$matched);
            $tempStr =  preg_replace($search, $replace, $matched[0]);        
            $tempStr =  preg_replace($search_js, $replace_js, $tempStr );
            
            return preg_replace($head ,$tempStr, $str);        
        }
    
    
        //test
        $str = '
        <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <link rel="stylesheet" type="text/css" href="../style/common.css "/>
            <link rel="stylesheet" type="text/css" href=\'../style/layout.CSS\'/>
            <link rel="stylesheet" type="text/css" href="../style/module.css"/>
            <script type="text/javascript" src="../script/jquery.min.js?v=1.3.2"></script>
            <script type="text/javascript" src="../script/jquery-ui.custom.min.js?v=1.7.3"></script>
            <script type="text/javascript" src="../script/commoned.js"></script>
            <script type="text/javascript" src="../script/base.js?v=0.0.1"></script>
            <script type="text/javascript" src="../script/apage.js"></script>
            <script type="text/javascript" src="../script/checklogin.js"></script>
            <script type="text/javascript" src="../script/pages/employee-add.js"></script>
            <title>test</title>
        </head>    
        <body>
        
        <input id="tst" class="btn" type = "button" value = "test css and jq"/>
        <script>
        alert($("#tst").attr("id"));
        </script>
        <div style = "margin:100px;">.css"    .js"</div>            
        </body>
        </html>
        ';
    
        echo "<hr />";
        echo addver($str,'1.0');  
        echo "<hr />";  
        
    ?>
  • 相关阅读:
    浅谈线性 Linear
    Github TinyRenderer渲染器课程实践记录
    蓝点无限UWB TDOA 低功耗标签 功耗测试
    UWB DW1000 BP30 测距代码架构
    C语言
    C语言
    张量tensor 和张量分解 tensor decomposition
    Manifold learning流行学习和谱聚类
    机器学习里面的核kernel, 维数灾难
    机器学习评价方法
  • 原文地址:https://www.cnblogs.com/ecalf/p/2791880.html
Copyright © 2011-2022 走看看