Subversion Repositories php-qbpwcf

Rev

Rev 226 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
218 liveuser 1
<?php
2
 
3
/*
4
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2025 Min-Jhin,Chen
7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#assets dir
29
$assetsDir="assets of phpLib::replaceMatchContent_20251206";
30
 
31
#複製原始檔案
32
#函式說明:
33
#複製檔案、資料夾.
34
#回傳結果:
35
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
36
#$result["error"],錯誤訊息.
37
#$result["function"],當前執行的函式名稱.
38
#$result["content"],複製好的檔案路徑與名稱.
39
#必填參數:
40
#$conf["file"],字串,檔案的位置與名稱.
41
$conf["file"]=$assetsDir."/fileOri.txt";
42
#$conf["to"],字串,檔案要複製到哪裡.
43
$conf["to"]=$assetsDir."/fileReplaced.txt";
44
#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
45
$conf["fileArgu"]=__FILE__;
46
#可省略參數:
47
#$conf["username"],字串,要以哪個使用者來執行,預設為執行該php程式的使用者.
48
#$conf["username"]="";
49
#$conf["password"],字串,使用者對應的密碼,預設不使用.
50
#$conf["password"]="";
51
#參考資料:
52
#無.
53
#備註:
54
#僅能在命令列環境下運行
55
$cp=cmd::cp($conf);
56
unset($conf);
57
 
58
#如果執行異常
59
if($cp["status"]==="false"){
60
 
61
	#debug
62
	var_dump($cp);
63
 
64
	#異常結束回傳1給shell
65
	exit(1);
66
 
67
	}#if end
68
 
69
#匯入 $formats
70
include($assetsDir."/formats.php");
71
 
72
#初始化儲存要替換內容的格式
73
$replaceTo=array();
74
 
75
#設置起始年份
76
$replaceTo[1]["yearFrom"]="2014";
77
 
78
#設置今年
79
$replaceTo[1]["yearTo"]=gmdate("Y");
80
 
81
#設置作者清單
82
$replaceTo[1]["Authors"]="MIN-ZHI, CHEN";
83
 
84
#函式說明:
85
#置換檔案內容中符合的內容.
86
#回傳結果:
87
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
88
#$reuslt["error"],執行不正常結束的錯訊息陣列.
89
#$result["function"],當前執行的函式名稱.
90
#$result["argu"],本函式使用的參數.
91
#$result["content"],更新後的檔案內容陣列.每個元素代表一行的內容.
92
#$result["found"],字串,是否有找到符合條件需要置換的內容.
93
#$result["relaceInfo"],陣列,記錄需要置換的行資訊,元素的key為需要置換的行號,第 $i 行用 $i+1 表示.
94
#$result["relaceInfo"][$i]["ori"],字串,第 $i+1 行原始的內容.
95
#$result["relaceInfo"][$i]["new"],字串,第 $i+1 行要置換成的內容.
96
#必填參數:
97
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
98
$conf["fileArgu"]=__FILE__;
99
#$conf["file"],字串,要置換內容的檔案路徑與名稱.
100
$conf["file"]=$assetsDir."/fileReplaced.txt";
101
#$conf["formats"],陣列,連續的關鍵字字串.
102
$conf["formats"]=$formats;
103
#$conf["replaceTo"],陣列,原始內容要如何置換,每個元素的索引對應到formats參數的每個元素,若其索引不存在則代表對應的行不異動.
104
$conf["replaceTo"]=$replaceTo;
105
#可省略參數:
106
#無.
107
#參考資料:
108
#無.
109
#備註:
110
#參數設定 $conf["replaceTo"][$i]=$replaceStr; 代表符合格式的連續字串中的 $i+1 行內容要置換成 $replaceStr.
111
#參數設定 $conf["replaceTo"][$i]=array("varName1"=>$replaceStr1,"varName2"=>$replaceStr2); 代表符合格式的連續字串中的 $i+1 行內容中的變數 varName1 要置換成 $replaceStr1;變數 varName2 要置換成 $replaceStr2.
112
$replaceMatchContent=phpLib::replaceMatchContent($conf);
113
unset($conf);
114
 
115
#debug
116
var_dump($replaceMatchContent);