格式化URL


 

 

//格式化url查詢參數為json
function formatUrl(url){ 
    var reg=/(?:[?&]+)([^&]+)=([^&]+)/g; 
    var data={}; 
    function fn(str,pro,value){ 
        data[decodeURIComponent(pro)]=decodeURIComponent(value); 
    } 
    url.replace(reg,fn); 
    return data; 
} 

 

 

 

//替換索引編號
function replaceIndex(str){

    var regExp = new RegExp('<%=(.*?)%>');
    var replaceText = Math.floor(Math.random()*100000000);
    var i = str.search('<%=(.*?)%>');
    var n = str.search(regExp);
    
    console.log('i ', i, n, typeof str);

    var newstr = str.replace(regExp,replaceText);
    //console.log( newstr );

    fs.writeFile(path, newstr, 'utf-8', function(err){
        console.log('backfill error',err);
    });
}

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM