Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*QBPWCF, Quick Build PHP website Component base on Fedora Linux.Copyright (C) 2014~2025 Min-Jhin,ChenThis file is part of QBPWCF.QBPWCF is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.QBPWCF is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with QBPWCF. If not, see <http://www.gnu.org/licenses/>.*/#使用命名空間qbpwcfnamespace qbpwcf;#assets dir$assetsDir="assets of phpLib::replaceMatchContent_20251206";#複製原始檔案#函式說明:#複製檔案、資料夾.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息.#$result["function"],當前執行的函式名稱.#$result["content"],複製好的檔案路徑與名稱.#必填參數:#$conf["file"],字串,檔案的位置與名稱.$conf["file"]=$assetsDir."/fileOri.txt";#$conf["to"],字串,檔案要複製到哪裡.$conf["to"]=$assetsDir."/fileReplaced.txt";#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.#$conf["username"]="";#$conf["password"],字串,使用者對應的密碼,預設不使用.#$conf["password"]="";#參考資料:#無.#備註:#僅能在命令列環境下運行$cp=cmd::cp($conf);unset($conf);#如果執行異常if($cp["status"]==="false"){#debugvar_dump($cp);#異常結束回傳1給shellexit(1);}#if end#匯入 $formatsinclude($assetsDir."/formats.php");#初始化儲存要替換內容的格式$replaceTo=array();#設置起始年份$replaceTo[1]["yearFrom"]="2014";#設置今年$replaceTo[1]["yearTo"]=gmdate("Y");#設置作者清單$replaceTo[1]["Authors"]="MIN-ZHI, CHEN";#函式說明:#置換檔案內容中符合的內容.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#$result["argu"],本函式使用的參數.#$result["content"],更新後的檔案內容陣列.每個元素代表一行的內容.#$result["found"],字串,是否有找到符合條件需要置換的內容.#$result["relaceInfo"],陣列,記錄需要置換的行資訊,元素的key為需要置換的行號,第 $i 行用 $i+1 表示.#$result["relaceInfo"][$i]["ori"],字串,第 $i+1 行原始的內容.#$result["relaceInfo"][$i]["new"],字串,第 $i+1 行要置換成的內容.#必填參數:#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#$conf["file"],字串,要置換內容的檔案路徑與名稱.$conf["file"]=$assetsDir."/fileReplaced.txt";#$conf["formats"],陣列,連續的關鍵字字串.$conf["formats"]=$formats;#$conf["replaceTo"],陣列,原始內容要如何置換,每個元素的索引對應到formats參數的每個元素,若其索引不存在則代表對應的行不異動.$conf["replaceTo"]=$replaceTo;#可省略參數:#無.#參考資料:#無.#備註:#參數設定 $conf["replaceTo"][$i]=$replaceStr; 代表符合格式的連續字串中的 $i+1 行內容要置換成 $replaceStr.#參數設定 $conf["replaceTo"][$i]=array("varName1"=>$replaceStr1,"varName2"=>$replaceStr2); 代表符合格式的連續字串中的 $i+1 行內容中的變數 varName1 要置換成 $replaceStr1;變數 varName2 要置換成 $replaceStr2.$replaceMatchContent=phpLib::replaceMatchContent($conf);unset($conf);#debugvar_dump($replaceMatchContent);