| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
liveuser |
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 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
與字串處理相關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class stringProcess{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#可省略參數:
|
|
|
45 |
#無.
|
|
|
46 |
#參考資料:
|
|
|
47 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
| 249 |
liveuser |
48 |
#get namespace and class=>https://www.php.net/manual/en/function.get-called-class.php
|
| 3 |
liveuser |
49 |
#備註:
|
|
|
50 |
#無.
|
|
|
51 |
*/
|
|
|
52 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
53 |
|
| 3 |
liveuser |
54 |
#取得當前執行的函式
|
|
|
55 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
56 |
|
| 3 |
liveuser |
57 |
#設置執行不正常
|
|
|
58 |
$result["status"]="false";
|
| 226 |
liveuser |
59 |
|
| 3 |
liveuser |
60 |
#設置執行錯誤
|
| 249 |
liveuser |
61 |
$result["error"][]="欲呼叫的". get_called_class()."->".$method."() 不存在!";
|
| 226 |
liveuser |
62 |
|
| 3 |
liveuser |
63 |
#設置所丟入的參數
|
|
|
64 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
65 |
|
| 3 |
liveuser |
66 |
#回傳結果
|
|
|
67 |
return $result;
|
| 226 |
liveuser |
68 |
|
| 3 |
liveuser |
69 |
}#function __call end
|
| 226 |
liveuser |
70 |
|
| 3 |
liveuser |
71 |
/*
|
|
|
72 |
#函式說明:
|
|
|
73 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
74 |
#回傳結果:
|
|
|
75 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
76 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
77 |
#$result["function"],當前執行的函式名稱.
|
|
|
78 |
#必填參數:
|
|
|
79 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
80 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
81 |
#可省略參數:
|
|
|
82 |
#無.
|
|
|
83 |
#參考資料:
|
|
|
84 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
| 249 |
liveuser |
85 |
#get namespace and class=>https://www.php.net/manual/en/function.get-called-class.php
|
| 3 |
liveuser |
86 |
#備註:
|
|
|
87 |
#無.
|
|
|
88 |
*/
|
|
|
89 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
90 |
|
| 3 |
liveuser |
91 |
#取得當前執行的函式
|
|
|
92 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
93 |
|
| 3 |
liveuser |
94 |
#設置執行不正常
|
|
|
95 |
$result["status"]="false";
|
| 226 |
liveuser |
96 |
|
| 3 |
liveuser |
97 |
#設置執行錯誤
|
| 249 |
liveuser |
98 |
$result["error"][]="欲呼叫的". get_called_class()."::".$method."() 不存在!";
|
| 226 |
liveuser |
99 |
|
| 3 |
liveuser |
100 |
#設置所丟入的參數
|
|
|
101 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
102 |
|
| 3 |
liveuser |
103 |
#回傳結果
|
|
|
104 |
return $result;
|
| 226 |
liveuser |
105 |
|
| 3 |
liveuser |
106 |
}#function __callStatic end
|
| 226 |
liveuser |
107 |
|
| 3 |
liveuser |
108 |
/*
|
|
|
109 |
#函式說明:
|
|
|
110 |
#將含有數個黑點的字串,處理成只剩下含有最後一個黑點的字串,結果會回傳合併後的字串。
|
|
|
111 |
#如果字串中沒有黑點則會回傳原始字串
|
|
|
112 |
#回傳結果:
|
|
|
113 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
114 |
#$result["error"],錯誤訊息陣列
|
|
|
115 |
#$result["function"],當前函數名稱
|
|
|
116 |
#$result["content"],只剩下最後一個黑點的字串
|
|
|
117 |
#必填參數:
|
|
|
118 |
#$conf["stringIn"],字串,爲要進行處理的字串
|
|
|
119 |
$conf["stringIn"]="";
|
|
|
120 |
#可省略參數:
|
|
|
121 |
#無.
|
|
|
122 |
#參考資料:
|
|
|
123 |
#無.
|
|
|
124 |
#備註:
|
|
|
125 |
#無.
|
|
|
126 |
*/
|
|
|
127 |
public static function solveDotProblems(&$conf){
|
|
|
128 |
|
|
|
129 |
#初始化要回傳的內容
|
|
|
130 |
$result=array();
|
| 226 |
liveuser |
131 |
|
| 3 |
liveuser |
132 |
#取得當前函數名稱
|
|
|
133 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
134 |
|
| 3 |
liveuser |
135 |
#如果 $conf 不為陣列
|
|
|
136 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
137 |
|
| 3 |
liveuser |
138 |
#設置執行失敗
|
|
|
139 |
$result["status"]="false";
|
| 226 |
liveuser |
140 |
|
| 3 |
liveuser |
141 |
#設置執行錯誤訊息
|
|
|
142 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
143 |
|
| 3 |
liveuser |
144 |
#如果傳入的參數為 null
|
|
|
145 |
if($conf==null){
|
| 226 |
liveuser |
146 |
|
| 3 |
liveuser |
147 |
#設置執行錯誤訊息
|
|
|
148 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
149 |
|
| 3 |
liveuser |
150 |
}#if end
|
| 226 |
liveuser |
151 |
|
| 3 |
liveuser |
152 |
#回傳結果
|
|
|
153 |
return $result;
|
| 226 |
liveuser |
154 |
|
| 3 |
liveuser |
155 |
}#if end
|
| 226 |
liveuser |
156 |
|
| 3 |
liveuser |
157 |
#初始化要回傳的語法
|
|
|
158 |
$result["content"]="";
|
|
|
159 |
|
|
|
160 |
#檢查參數
|
|
|
161 |
#函式說明:
|
|
|
162 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
163 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
164 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
165 |
#$result["function"],當前執行的函式名稱.
|
|
|
166 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
167 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
168 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
169 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
170 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
171 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
172 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
173 |
#必填寫的參數:
|
|
|
174 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
175 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
176 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
177 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
178 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
179 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
180 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
181 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
182 |
#可以省略的參數:
|
|
|
183 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
184 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
185 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
186 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ssl","serverIp","port");
|
| 226 |
liveuser |
187 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
188 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
189 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
190 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","127.0.0.1",null);
|
|
|
191 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
192 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
193 |
#參考資料來源:
|
|
|
194 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
195 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
196 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
197 |
|
| 3 |
liveuser |
198 |
#如果檢查失敗
|
|
|
199 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
200 |
|
| 3 |
liveuser |
201 |
#設置執行不正常
|
|
|
202 |
$result["status"]="false";
|
| 226 |
liveuser |
203 |
|
| 3 |
liveuser |
204 |
#設置錯誤訊息
|
|
|
205 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
206 |
|
| 3 |
liveuser |
207 |
#回傳結果
|
|
|
208 |
return $result;
|
| 226 |
liveuser |
209 |
|
| 3 |
liveuser |
210 |
}#if end
|
| 226 |
liveuser |
211 |
|
| 3 |
liveuser |
212 |
#如果檢查不通過
|
|
|
213 |
if($checkResult["passed"]=="false"){
|
|
|
214 |
|
|
|
215 |
#設置執行不正常
|
|
|
216 |
$result["status"]="false";
|
| 226 |
liveuser |
217 |
|
| 3 |
liveuser |
218 |
#設置錯誤訊息
|
|
|
219 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
220 |
|
| 3 |
liveuser |
221 |
#回傳結果
|
|
|
222 |
return $result;
|
|
|
223 |
|
|
|
224 |
}#if end
|
|
|
225 |
|
|
|
226 |
#宣告$str為string
|
|
|
227 |
$str = "";
|
|
|
228 |
|
|
|
229 |
#取得該字串有幾個"."
|
| 226 |
liveuser |
230 |
$numberDot = substr_count($conf["stringIn"],".");
|
|
|
231 |
|
| 3 |
liveuser |
232 |
#開始分離
|
|
|
233 |
$changedString = explode(".",$conf["stringIn"]);
|
|
|
234 |
|
|
|
235 |
#開始重組
|
|
|
236 |
for($i=0;$i<=($numberDot-1);$i++){
|
|
|
237 |
|
|
|
238 |
#將黑點前的所有字串合併
|
|
|
239 |
$str = $str.$changedString[$i];
|
| 226 |
liveuser |
240 |
|
| 3 |
liveuser |
241 |
}#for end
|
|
|
242 |
|
|
|
243 |
#如果黑點不等於0個
|
|
|
244 |
if($numberDot!=0){
|
|
|
245 |
|
|
|
246 |
#加上黑點
|
|
|
247 |
$str = $str.".";
|
| 226 |
liveuser |
248 |
|
| 3 |
liveuser |
249 |
#加上副檔名
|
|
|
250 |
$str = $str.$changedString[$numberDot];
|
| 226 |
liveuser |
251 |
|
| 3 |
liveuser |
252 |
#設置執行正常
|
|
|
253 |
$result["status"]="true";
|
| 226 |
liveuser |
254 |
|
| 3 |
liveuser |
255 |
#設置要回傳的字串
|
|
|
256 |
$result["content"]=$str;
|
| 226 |
liveuser |
257 |
|
| 3 |
liveuser |
258 |
#回傳結果
|
|
|
259 |
return $result;
|
| 226 |
liveuser |
260 |
|
| 3 |
liveuser |
261 |
}#if end
|
| 226 |
liveuser |
262 |
|
| 3 |
liveuser |
263 |
#反之,代表沒有副檔名
|
|
|
264 |
else{
|
| 226 |
liveuser |
265 |
|
| 3 |
liveuser |
266 |
#設置執行正常
|
|
|
267 |
$result["status"]="true";
|
| 226 |
liveuser |
268 |
|
| 3 |
liveuser |
269 |
#設置要回傳的字串
|
|
|
270 |
$result["content"]=$conf["stringIn"];
|
| 226 |
liveuser |
271 |
|
| 3 |
liveuser |
272 |
#回傳結果
|
|
|
273 |
return $result;
|
| 226 |
liveuser |
274 |
|
| 3 |
liveuser |
275 |
}#else end
|
| 226 |
liveuser |
276 |
|
| 3 |
liveuser |
277 |
}#function solveDotProblems end
|
|
|
278 |
|
|
|
279 |
/*
|
|
|
280 |
#函式說明:
|
|
|
281 |
#將固定格式的字串開頭移除一個,例如"a,b,c,null"變成"b,c,null"
|
|
|
282 |
#回傳結果:
|
|
|
283 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
284 |
#$result["error"],錯誤訊息陣列
|
|
|
285 |
#$result["function"],當前執行的函數名稱.
|
|
|
286 |
#$result["argu"],使用的參數.
|
|
|
287 |
#$result["dropElement"],被丟棄的元素.
|
|
|
288 |
#必填參數:
|
|
|
289 |
#$conf["stringIn"],字串,要處理的字串。
|
|
|
290 |
$conf["stringIn"]="";
|
|
|
291 |
#可省略參數:
|
|
|
292 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割,預設為",".
|
|
|
293 |
#$conf["spiltSymbol"]="";
|
|
|
294 |
#$conf["unshift"],字串,是否要改成丟棄最後一個元素,預設為"false";反之為"true".
|
|
|
295 |
#$conf["unshift"]="false";
|
|
|
296 |
#參考資料:
|
|
|
297 |
#無.
|
|
|
298 |
#備註:
|
|
|
299 |
#無.
|
|
|
300 |
*/
|
|
|
301 |
public static function stringShift(&$conf){
|
| 226 |
liveuser |
302 |
|
| 3 |
liveuser |
303 |
#檢查參數
|
|
|
304 |
#函式說明:
|
|
|
305 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
306 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
307 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
308 |
#$result["function"],當前執行的函式名稱.
|
|
|
309 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
310 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
311 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
312 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
313 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
314 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
315 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
316 |
#必填寫的參數:
|
|
|
317 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
318 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
319 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
320 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
321 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
322 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
323 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
324 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
325 |
#可以省略的參數:
|
|
|
326 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
327 |
#$conf["canBeEmptyString"]="false";
|
|
|
328 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
329 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("spiltSymbol","unshift");
|
| 226 |
liveuser |
330 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
331 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
332 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
333 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(",","false");
|
|
|
334 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
335 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
336 |
#參考資料來源:
|
|
|
337 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
338 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
339 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
340 |
|
|
|
341 |
#如果檢查有誤
|
|
|
342 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
343 |
|
| 3 |
liveuser |
344 |
#設置錯誤識別
|
|
|
345 |
$result["status"]="false";
|
| 226 |
liveuser |
346 |
|
| 3 |
liveuser |
347 |
#設置錯誤訊息
|
|
|
348 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
349 |
|
| 3 |
liveuser |
350 |
#回傳結果
|
|
|
351 |
return $result;
|
| 226 |
liveuser |
352 |
|
| 3 |
liveuser |
353 |
}#if end
|
| 226 |
liveuser |
354 |
|
| 3 |
liveuser |
355 |
#如果檢查不通過
|
|
|
356 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
357 |
|
| 3 |
liveuser |
358 |
#設置錯誤識別
|
|
|
359 |
$result["status"]="false";
|
| 226 |
liveuser |
360 |
|
| 3 |
liveuser |
361 |
#設置錯誤訊息
|
|
|
362 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
363 |
|
| 3 |
liveuser |
364 |
#回傳結果
|
|
|
365 |
return $result;
|
| 226 |
liveuser |
366 |
|
| 3 |
liveuser |
367 |
}#if end
|
| 226 |
liveuser |
368 |
|
| 3 |
liveuser |
369 |
#函式說明:
|
|
|
370 |
#將特定符號間隔的字串"a,b,c"變成陣列.
|
|
|
371 |
#回傳結果:
|
|
|
372 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
373 |
#$result["function"],當前執行的function名稱.
|
|
|
374 |
#$result["argu"],使用的參數.
|
|
|
375 |
#$result["error"],錯誤訊息陣列.
|
|
|
376 |
#$result["content"],處理好的內容.
|
|
|
377 |
#必填參數:
|
|
|
378 |
#$conf["inputStr"],字串,要轉一維陣列的字串
|
|
|
379 |
$conf["arrays::stringToArray"]["inputStr"]=$conf["stringIn"];
|
|
|
380 |
#可省略參數:
|
|
|
381 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為","
|
|
|
382 |
$conf["arrays::stringToArray"]["spiltSymbol"]=$conf["spiltSymbol"];
|
|
|
383 |
$stringToArray=arrays::stringToArray($conf["arrays::stringToArray"]);
|
|
|
384 |
unset($conf["arrays::stringToArray"]);
|
| 226 |
liveuser |
385 |
|
| 3 |
liveuser |
386 |
#如果轉換失敗
|
|
|
387 |
if($stringToArray["status"]==="false"){
|
| 226 |
liveuser |
388 |
|
| 3 |
liveuser |
389 |
#設置錯誤識別
|
|
|
390 |
$result["status"]="false";
|
| 226 |
liveuser |
391 |
|
| 3 |
liveuser |
392 |
#設置錯誤訊息
|
|
|
393 |
$result["error"]=$stringToArray;
|
| 226 |
liveuser |
394 |
|
| 3 |
liveuser |
395 |
#回傳結果
|
|
|
396 |
return $result;
|
| 226 |
liveuser |
397 |
|
| 3 |
liveuser |
398 |
}#if end
|
| 226 |
liveuser |
399 |
|
| 3 |
liveuser |
400 |
#取得分割好的陣列
|
|
|
401 |
$array=$stringToArray["content"];
|
| 226 |
liveuser |
402 |
|
| 3 |
liveuser |
403 |
#如果沒有要丟棄結尾元素
|
|
|
404 |
if($conf["unshift"]==="false"){
|
| 226 |
liveuser |
405 |
|
| 3 |
liveuser |
406 |
#取得被丟棄的元素
|
|
|
407 |
$result["dropElement"]=array_shift($array);
|
| 226 |
liveuser |
408 |
|
| 3 |
liveuser |
409 |
}#if end
|
| 226 |
liveuser |
410 |
|
| 3 |
liveuser |
411 |
#反之要丟棄開頭元素
|
|
|
412 |
else{
|
| 226 |
liveuser |
413 |
|
| 3 |
liveuser |
414 |
#取得被丟棄的元素,參考資料https://www.php.net/manual/en/function.array-pop.php
|
|
|
415 |
$result["dropElement"]=array_pop($array);
|
| 226 |
liveuser |
416 |
|
| 3 |
liveuser |
417 |
}#else end
|
| 226 |
liveuser |
418 |
|
| 3 |
liveuser |
419 |
#函式說明:
|
|
|
420 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
421 |
#回傳結果:
|
|
|
422 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
423 |
#$result["function"],當前執行的function名稱
|
|
|
424 |
#$result["error"],錯誤訊息陣列.
|
|
|
425 |
#$result["content"],處理好的字串.
|
|
|
426 |
#$result["argu"],使用的參數.
|
|
|
427 |
#必填參數:
|
|
|
428 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
429 |
$conf["arrays::arrayToString"]["inputArray"]=$array;
|
|
|
430 |
#可省略參數:
|
|
|
431 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
432 |
$conf["arrays::arrayToString"]["spiltSymbol"]=$conf["spiltSymbol"];
|
|
|
433 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
434 |
$conf["arrays::arrayToString"]["skipEnd"]="true";
|
|
|
435 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
436 |
unset($conf["arrays::arrayToString"]);
|
| 226 |
liveuser |
437 |
|
| 3 |
liveuser |
438 |
#如果轉換失敗
|
|
|
439 |
if($arrayToString["status"]==="false"){
|
| 226 |
liveuser |
440 |
|
| 3 |
liveuser |
441 |
#設置錯誤識別
|
|
|
442 |
$result["status"]="false";
|
| 226 |
liveuser |
443 |
|
| 3 |
liveuser |
444 |
#設置錯誤訊息
|
|
|
445 |
$result["error"]=$arrayToString;
|
| 226 |
liveuser |
446 |
|
| 3 |
liveuser |
447 |
#回傳結果
|
|
|
448 |
return $result;
|
| 226 |
liveuser |
449 |
|
| 3 |
liveuser |
450 |
}#if end
|
| 226 |
liveuser |
451 |
|
| 3 |
liveuser |
452 |
#取得處理好的字串
|
|
|
453 |
$result["content"]=$arrayToString["content"];
|
| 226 |
liveuser |
454 |
|
| 3 |
liveuser |
455 |
#設置執行正常
|
|
|
456 |
$result["status"]="true";
|
| 226 |
liveuser |
457 |
|
| 3 |
liveuser |
458 |
#回傳結果
|
|
|
459 |
return $result;
|
| 226 |
liveuser |
460 |
|
| 3 |
liveuser |
461 |
}#function stringShift end
|
|
|
462 |
|
|
|
463 |
/*
|
|
|
464 |
#函式說明:
|
|
|
465 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
466 |
#回傳結果:
|
|
|
467 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
468 |
#$result["error"],錯誤訊息陣列
|
|
|
469 |
#$result["function"],當前執行的函數名稱.
|
|
|
470 |
#$result["argu"],使用的參數.
|
|
|
471 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
472 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
473 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
474 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
475 |
#必填參數:
|
|
|
476 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
477 |
$conf["stringIn"]="";
|
|
|
478 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
479 |
$conf["spiltSymbol"]="";
|
|
|
480 |
#可省略參數:
|
|
|
481 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
482 |
#$conf["allowEmptyStr"]="false";
|
|
|
483 |
#參考資料:
|
|
|
484 |
#無.
|
|
|
485 |
#備註:
|
|
|
486 |
#無.
|
|
|
487 |
*/
|
|
|
488 |
public static function spiltString(&$conf){
|
|
|
489 |
|
|
|
490 |
#初始化要回傳的內容
|
|
|
491 |
$result=array();
|
|
|
492 |
|
|
|
493 |
#取得當前執行的函數名稱
|
|
|
494 |
$result["function"]=__FUNCTION__;
|
|
|
495 |
|
|
|
496 |
#如果 $conf 不為陣列
|
|
|
497 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
498 |
|
| 3 |
liveuser |
499 |
#設置執行失敗
|
|
|
500 |
$result["status"]="false";
|
| 226 |
liveuser |
501 |
|
| 3 |
liveuser |
502 |
#設置執行錯誤訊息
|
|
|
503 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
504 |
|
|
|
505 |
#如果傳入的參數為 null
|
|
|
506 |
if($conf==null){
|
| 226 |
liveuser |
507 |
|
| 3 |
liveuser |
508 |
#設置執行錯誤訊息
|
|
|
509 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
510 |
|
| 3 |
liveuser |
511 |
}#if end
|
|
|
512 |
|
|
|
513 |
#回傳結果
|
|
|
514 |
return $result;
|
| 226 |
liveuser |
515 |
|
| 3 |
liveuser |
516 |
}#if end
|
|
|
517 |
|
|
|
518 |
#記錄使用的參數
|
|
|
519 |
$result["argu"]=$conf;
|
|
|
520 |
|
|
|
521 |
#檢查參數
|
|
|
522 |
#函式說明:
|
|
|
523 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
524 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
525 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
526 |
#$result["function"],當前執行的函式名稱.
|
|
|
527 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
528 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
529 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
530 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
531 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
532 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
533 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
534 |
#必填寫的參數:
|
|
|
535 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
536 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
537 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
538 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","spiltSymbol");
|
| 226 |
liveuser |
539 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
540 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
541 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
542 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
543 |
#可以省略的參數:
|
|
|
544 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
545 |
#$conf["canBeEmptyString"]="false";
|
|
|
546 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
547 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("allowEmptyStr");
|
| 226 |
liveuser |
548 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
549 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
550 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
551 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
552 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
553 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
554 |
#參考資料來源:
|
|
|
555 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
556 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
557 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
558 |
|
|
|
559 |
#如果檢查有誤
|
|
|
560 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
561 |
|
| 3 |
liveuser |
562 |
#設置錯誤識別
|
|
|
563 |
$result["status"]="false";
|
| 226 |
liveuser |
564 |
|
| 3 |
liveuser |
565 |
#設置錯誤訊息
|
|
|
566 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
567 |
|
| 3 |
liveuser |
568 |
#回傳結果
|
|
|
569 |
return $result;
|
| 226 |
liveuser |
570 |
|
| 3 |
liveuser |
571 |
}#if end
|
| 226 |
liveuser |
572 |
|
| 3 |
liveuser |
573 |
#如果檢查不通過
|
|
|
574 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
575 |
|
| 3 |
liveuser |
576 |
#設置錯誤識別
|
|
|
577 |
$result["status"]="false";
|
| 226 |
liveuser |
578 |
|
| 3 |
liveuser |
579 |
#設置錯誤訊息
|
|
|
580 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
581 |
|
| 3 |
liveuser |
582 |
#回傳結果
|
|
|
583 |
return $result;
|
| 226 |
liveuser |
584 |
|
| 3 |
liveuser |
585 |
}#if end
|
| 226 |
liveuser |
586 |
|
| 3 |
liveuser |
587 |
#取得 $conf["stringIn"] 的 unicode 長度
|
|
|
588 |
$stringInLength=mb_strlen($conf["stringIn"],"UTF-8");
|
| 226 |
liveuser |
589 |
|
| 3 |
liveuser |
590 |
#取得 $conf["spiltSymbol"] 的 unicode 長度
|
|
|
591 |
$spiltSymbolLength=mb_strlen($conf["spiltSymbol"],"UTF-8");
|
| 226 |
liveuser |
592 |
|
| 3 |
liveuser |
593 |
#置換$conf["stringIn"]成unicode字串
|
|
|
594 |
$conf["stringIn"]=mb_substr($conf["stringIn"],0,$stringInLength,"UTF-8");
|
| 226 |
liveuser |
595 |
|
| 3 |
liveuser |
596 |
#置換$conf["spiltSymbol"]成unicode字串
|
| 226 |
liveuser |
597 |
$conf["spiltSymbol"]=mb_substr($conf["spiltSymbol"],0,$spiltSymbolLength,"UTF-8");
|
| 3 |
liveuser |
598 |
|
|
|
599 |
#var_dump($conf["spiltSymbol"]);
|
|
|
600 |
|
|
|
601 |
#取得該字串有幾個 $conf["spiltSymbol"]
|
| 226 |
liveuser |
602 |
$numberSymbol=substr_count($conf["stringIn"],$conf["spiltSymbol"]);
|
| 3 |
liveuser |
603 |
|
|
|
604 |
#如果裡面有分割用的符號
|
|
|
605 |
if($numberSymbol!==0){
|
|
|
606 |
|
|
|
607 |
#設置沒有找到分割用的關鍵字
|
|
|
608 |
$result["found"]="true";
|
|
|
609 |
|
|
|
610 |
#依據 $spiltSymbol 分割,並將陣列變數存到 $result["dataArray"]
|
| 226 |
liveuser |
611 |
$result["dataArray"]=explode($conf["spiltSymbol"],$conf["stringIn"]);
|
| 3 |
liveuser |
612 |
|
|
|
613 |
#如果分割出來的結果是空的
|
|
|
614 |
if(count($result["dataArray"])==0){
|
| 226 |
liveuser |
615 |
|
| 3 |
liveuser |
616 |
#取得總共有多少段
|
|
|
617 |
$result["dataCounts"]=0;
|
| 226 |
liveuser |
618 |
|
| 3 |
liveuser |
619 |
}#if end
|
| 226 |
liveuser |
620 |
|
|
|
621 |
#反之分割出來不是空的
|
| 3 |
liveuser |
622 |
else{
|
|
|
623 |
|
|
|
624 |
#如果存在最後一個選項
|
|
|
625 |
if(isset($result["dataArray"][count($result["dataArray"])-1])){
|
|
|
626 |
|
|
|
627 |
#如果最後一個選項為空
|
|
|
628 |
if($result["dataArray"][count($result["dataArray"])-1]==""){
|
| 226 |
liveuser |
629 |
|
| 3 |
liveuser |
630 |
#卸除該元素
|
|
|
631 |
unset($result["dataArray"][count($result["dataArray"])-1]);
|
| 226 |
liveuser |
632 |
|
| 3 |
liveuser |
633 |
}#if end
|
| 226 |
liveuser |
634 |
|
| 3 |
liveuser |
635 |
}#if end
|
| 226 |
liveuser |
636 |
|
| 3 |
liveuser |
637 |
#取得總共有多少段
|
|
|
638 |
$result["dataCounts"]=count($result["dataArray"]);
|
| 226 |
liveuser |
639 |
|
| 3 |
liveuser |
640 |
}#else end
|
|
|
641 |
|
|
|
642 |
#取得原始要分割的字串
|
|
|
643 |
$result["oriStr"]=$conf["stringIn"];
|
|
|
644 |
|
|
|
645 |
}#if end
|
| 226 |
liveuser |
646 |
|
| 3 |
liveuser |
647 |
#反之
|
|
|
648 |
else{
|
| 226 |
liveuser |
649 |
|
| 3 |
liveuser |
650 |
#設置只有一個片段
|
|
|
651 |
$result["dataCounts"]=1;
|
| 226 |
liveuser |
652 |
|
| 3 |
liveuser |
653 |
#取得第一個片段亦即原始字串的內容
|
|
|
654 |
$result["dataArray"][0]=$conf["stringIn"];
|
|
|
655 |
|
|
|
656 |
#取得原始要分割的字串
|
|
|
657 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
658 |
|
| 3 |
liveuser |
659 |
#設置沒有找到分割用的關鍵字
|
|
|
660 |
$result["found"]="false";
|
| 226 |
liveuser |
661 |
|
| 3 |
liveuser |
662 |
}#else end
|
| 226 |
liveuser |
663 |
|
|
|
664 |
#如果不允許分割出空字串
|
| 3 |
liveuser |
665 |
if($conf["allowEmptyStr"]=="false"){
|
| 226 |
liveuser |
666 |
|
| 3 |
liveuser |
667 |
#依據 $result["dataCounts"] 檢查分割好的片段內容是否有含有 "" 的內容
|
|
|
668 |
for($i=0;$i<$result["dataCounts"];$i++){
|
| 226 |
liveuser |
669 |
|
| 3 |
liveuser |
670 |
#如果 分割好的片段內容含有 "" 的內容
|
|
|
671 |
if($result["dataArray"][$i]==""){
|
| 226 |
liveuser |
672 |
|
| 3 |
liveuser |
673 |
#卸除其變數內容
|
|
|
674 |
unset($result["dataArray"][$i]);
|
| 226 |
liveuser |
675 |
|
| 3 |
liveuser |
676 |
}#if end
|
| 226 |
liveuser |
677 |
|
| 3 |
liveuser |
678 |
}#for end
|
| 226 |
liveuser |
679 |
|
| 3 |
liveuser |
680 |
#重新計數目前分割成幾段內容
|
|
|
681 |
$result["dataCounts"]=count($result["dataArray"]);
|
| 226 |
liveuser |
682 |
|
| 3 |
liveuser |
683 |
#初始化計數當前要儲存的片段其key爲何
|
|
|
684 |
$cilpKey=0;
|
| 226 |
liveuser |
685 |
|
| 3 |
liveuser |
686 |
#重新排序分割好片段的k
|
|
|
687 |
foreach($result["dataArray"] as $cilpOriKey => $clipValue){
|
| 226 |
liveuser |
688 |
|
| 3 |
liveuser |
689 |
#卸除原始元素所屬key的變數
|
|
|
690 |
unset($result["dataArray"][$cilpOriKey]);
|
| 226 |
liveuser |
691 |
|
| 3 |
liveuser |
692 |
#取得片段的內容,並指派key
|
|
|
693 |
$result["dataArray"][$cilpKey]=$clipValue;
|
| 226 |
liveuser |
694 |
|
| 3 |
liveuser |
695 |
#計數當前要儲存片段的key+1
|
|
|
696 |
$cilpKey++;
|
| 226 |
liveuser |
697 |
|
| 3 |
liveuser |
698 |
}#foreache end
|
| 226 |
liveuser |
699 |
|
| 3 |
liveuser |
700 |
}#if end
|
| 226 |
liveuser |
701 |
|
| 3 |
liveuser |
702 |
#執行到這邊代表執行正常
|
|
|
703 |
$result["status"]="true";
|
| 226 |
liveuser |
704 |
|
| 3 |
liveuser |
705 |
#回傳結果
|
|
|
706 |
return $result;
|
|
|
707 |
|
|
|
708 |
}#funcion spiltString end
|
| 226 |
liveuser |
709 |
|
| 33 |
liveuser |
710 |
/*
|
|
|
711 |
#函式說明:
|
|
|
712 |
#將mutf7的字串轉成uft8
|
|
|
713 |
#回傳結果:
|
|
|
714 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
715 |
#$result["error"],錯誤訊息陣列.
|
|
|
716 |
#$result["function"],當前執行的函數名稱.
|
|
|
717 |
#$result["content"],轉好的字串.
|
|
|
718 |
#必填參數:
|
|
|
719 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
720 |
$conf["stringIn"]="";
|
|
|
721 |
#可省略參數:
|
|
|
722 |
#無.
|
|
|
723 |
#參考資料:
|
|
|
724 |
#https://www.php.net/manual/en/function.mb-convert-encoding.php
|
|
|
725 |
#https://www.php.net/manual/en/mbstring.supported-encodings.php
|
|
|
726 |
#備註:
|
|
|
727 |
#無.
|
|
|
728 |
*/
|
|
|
729 |
public static function utf7_imap_to_utf8($conf){
|
| 226 |
liveuser |
730 |
|
| 33 |
liveuser |
731 |
#初始化要回傳的內容
|
|
|
732 |
$result=array();
|
|
|
733 |
|
|
|
734 |
#取得當前執行的函數名稱
|
|
|
735 |
$result["function"]=__FUNCTION__;
|
|
|
736 |
|
|
|
737 |
#如果 $conf 不為陣列
|
|
|
738 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
739 |
|
| 33 |
liveuser |
740 |
#設置執行失敗
|
|
|
741 |
$result["status"]="false";
|
| 226 |
liveuser |
742 |
|
| 33 |
liveuser |
743 |
#設置執行錯誤訊息
|
|
|
744 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
745 |
|
|
|
746 |
#如果傳入的參數為 null
|
|
|
747 |
if($conf==null){
|
| 226 |
liveuser |
748 |
|
| 33 |
liveuser |
749 |
#設置執行錯誤訊息
|
|
|
750 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
751 |
|
| 33 |
liveuser |
752 |
}#if end
|
|
|
753 |
|
|
|
754 |
#回傳結果
|
|
|
755 |
return $result;
|
| 226 |
liveuser |
756 |
|
| 33 |
liveuser |
757 |
}#if end
|
|
|
758 |
|
|
|
759 |
#檢查參數
|
|
|
760 |
#函式說明:
|
|
|
761 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
762 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
763 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
764 |
#$result["function"],當前執行的函式名稱.
|
|
|
765 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
766 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
767 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
768 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
769 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
770 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
771 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
772 |
#必填寫的參數:
|
|
|
773 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
774 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
775 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
776 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
777 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 33 |
liveuser |
778 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
779 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
780 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
781 |
#可以省略的參數:
|
|
|
782 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
783 |
#$conf["canBeEmptyString"]="false";
|
|
|
784 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
785 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
786 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 33 |
liveuser |
787 |
#$conf["skipableVariableType"]=array();
|
|
|
788 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
789 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
790 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
791 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
792 |
#參考資料來源:
|
|
|
793 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
794 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
795 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
796 |
|
|
|
797 |
#如果檢查有誤
|
|
|
798 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
799 |
|
| 33 |
liveuser |
800 |
#設置錯誤識別
|
|
|
801 |
$result["status"]="false";
|
| 226 |
liveuser |
802 |
|
| 33 |
liveuser |
803 |
#設置錯誤訊息
|
|
|
804 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
805 |
|
| 33 |
liveuser |
806 |
#回傳結果
|
|
|
807 |
return $result;
|
| 226 |
liveuser |
808 |
|
| 33 |
liveuser |
809 |
}#if end
|
| 226 |
liveuser |
810 |
|
| 33 |
liveuser |
811 |
#如果檢查不通過
|
|
|
812 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
813 |
|
| 33 |
liveuser |
814 |
#設置錯誤識別
|
|
|
815 |
$result["status"]="false";
|
| 226 |
liveuser |
816 |
|
| 33 |
liveuser |
817 |
#設置錯誤訊息
|
|
|
818 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
819 |
|
| 33 |
liveuser |
820 |
#回傳結果
|
|
|
821 |
return $result;
|
| 226 |
liveuser |
822 |
|
| 33 |
liveuser |
823 |
}#if end
|
| 226 |
liveuser |
824 |
|
| 33 |
liveuser |
825 |
#取得轉好編碼的內容
|
|
|
826 |
$result["content"]=mb_convert_encoding($conf["stringIn"],"UTF8","UTF7-IMAP");
|
| 226 |
liveuser |
827 |
|
| 33 |
liveuser |
828 |
#設置執行正常
|
|
|
829 |
$result["status"]="true";
|
| 226 |
liveuser |
830 |
|
| 33 |
liveuser |
831 |
#回傳結果
|
|
|
832 |
return $result;
|
| 226 |
liveuser |
833 |
|
| 33 |
liveuser |
834 |
}#function utf7_imap_to_utf8 end
|
| 226 |
liveuser |
835 |
|
| 3 |
liveuser |
836 |
/*
|
|
|
837 |
#函式說明:
|
|
|
838 |
#將多個固定格式的字串分開,並回傳分開的結果
|
|
|
839 |
#回傳結果:
|
|
|
840 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
841 |
#$result["error"],錯誤訊息陣列.
|
|
|
842 |
#$result["function"],當前執行的函數名稱.
|
|
|
843 |
#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
|
|
|
844 |
#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
|
|
|
845 |
#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
|
|
|
846 |
#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
|
|
|
847 |
#必填參數:
|
|
|
848 |
#$conf["stringIn"],字串陣列,要處理的字串陣列.
|
|
|
849 |
$conf["stringIn"]=array();
|
|
|
850 |
#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
|
|
|
851 |
$conf["spiltSymbol"]="";
|
|
|
852 |
#可省略參數:
|
|
|
853 |
#無.
|
|
|
854 |
#參考資料:
|
|
|
855 |
#無.
|
|
|
856 |
#備註:
|
|
|
857 |
#無.
|
|
|
858 |
*/
|
|
|
859 |
public static function spiltMutiString(&$conf){
|
|
|
860 |
|
|
|
861 |
#初始化要回傳的內容
|
|
|
862 |
$result=array();
|
|
|
863 |
|
|
|
864 |
#取得當前執行的函數名稱
|
|
|
865 |
$result["function"]=__FUNCTION__;
|
|
|
866 |
|
|
|
867 |
#如果 $conf 不為陣列
|
|
|
868 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
869 |
|
| 3 |
liveuser |
870 |
#設置執行失敗
|
|
|
871 |
$result["status"]="false";
|
| 226 |
liveuser |
872 |
|
| 3 |
liveuser |
873 |
#設置執行錯誤訊息
|
|
|
874 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
875 |
|
|
|
876 |
#如果傳入的參數為 null
|
|
|
877 |
if($conf==null){
|
| 226 |
liveuser |
878 |
|
| 3 |
liveuser |
879 |
#設置執行錯誤訊息
|
|
|
880 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
881 |
|
| 3 |
liveuser |
882 |
}#if end
|
|
|
883 |
|
|
|
884 |
#回傳結果
|
|
|
885 |
return $result;
|
| 226 |
liveuser |
886 |
|
| 3 |
liveuser |
887 |
}#if end
|
|
|
888 |
|
|
|
889 |
#檢查參數
|
|
|
890 |
#函式說明:
|
|
|
891 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
892 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
893 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
894 |
#$result["function"],當前執行的函式名稱.
|
|
|
895 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
896 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
897 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
898 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
899 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
900 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
901 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
902 |
#必填寫的參數:
|
|
|
903 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
904 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
905 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
906 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","spiltSymbol");
|
| 226 |
liveuser |
907 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
908 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
909 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
910 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
911 |
#可以省略的參數:
|
|
|
912 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
913 |
#$conf["canBeEmptyString"]="false";
|
|
|
914 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
915 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
916 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
917 |
#$conf["skipableVariableType"]=array();
|
|
|
918 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
919 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
920 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
921 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
922 |
#參考資料來源:
|
|
|
923 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
924 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
925 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
926 |
|
|
|
927 |
#如果檢查有誤
|
|
|
928 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
929 |
|
| 3 |
liveuser |
930 |
#設置錯誤識別
|
|
|
931 |
$result["status"]="false";
|
| 226 |
liveuser |
932 |
|
| 3 |
liveuser |
933 |
#設置錯誤訊息
|
|
|
934 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
935 |
|
| 3 |
liveuser |
936 |
#回傳結果
|
|
|
937 |
return $result;
|
| 226 |
liveuser |
938 |
|
| 3 |
liveuser |
939 |
}#if end
|
| 226 |
liveuser |
940 |
|
| 3 |
liveuser |
941 |
#如果檢查不通過
|
|
|
942 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
943 |
|
| 3 |
liveuser |
944 |
#設置錯誤識別
|
|
|
945 |
$result["status"]="false";
|
| 226 |
liveuser |
946 |
|
| 3 |
liveuser |
947 |
#設置錯誤訊息
|
|
|
948 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
949 |
|
| 3 |
liveuser |
950 |
#回傳結果
|
|
|
951 |
return $result;
|
| 226 |
liveuser |
952 |
|
| 3 |
liveuser |
953 |
}#if end
|
| 226 |
liveuser |
954 |
|
| 3 |
liveuser |
955 |
#初始化 $result_spiltString
|
|
|
956 |
$result_spiltString=array();
|
|
|
957 |
|
|
|
958 |
#根據有幾個字串要進行切割,就執行幾次
|
|
|
959 |
#for($i=0;$i<count($conf["stringIn"]);$i++){
|
|
|
960 |
foreach($conf["stringIn"] as $key=>$value){
|
|
|
961 |
|
|
|
962 |
#debug
|
|
|
963 |
#var_dump($conf["stringIn"]);
|
|
|
964 |
|
|
|
965 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
966 |
#回傳的參數:
|
|
|
967 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
968 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
969 |
#必填參數:
|
|
|
970 |
$conf_spiltString["stringIn"]=$value;#要處理的字串。
|
|
|
971 |
$conf_spiltString["spiltSymbol"]=$conf["spiltSymbol"];#爲以哪個符號作爲分割
|
|
|
972 |
$spiltString=stringProcess::spiltString($conf_spiltString);
|
|
|
973 |
unset($conf_spiltString);
|
| 226 |
liveuser |
974 |
|
| 3 |
liveuser |
975 |
#如果分開字串失敗
|
|
|
976 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
977 |
|
| 3 |
liveuser |
978 |
#設置錯誤識別
|
|
|
979 |
$result["status"]="false";
|
| 226 |
liveuser |
980 |
|
| 3 |
liveuser |
981 |
#設置錯誤訊息
|
|
|
982 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
983 |
|
| 3 |
liveuser |
984 |
#回傳結果
|
|
|
985 |
return $result;
|
| 226 |
liveuser |
986 |
|
| 3 |
liveuser |
987 |
}#if end
|
| 226 |
liveuser |
988 |
|
| 3 |
liveuser |
989 |
#取得分割字串後的結果
|
|
|
990 |
$result_spiltString[]=$spiltString;
|
|
|
991 |
|
|
|
992 |
}#for end
|
| 226 |
liveuser |
993 |
|
| 3 |
liveuser |
994 |
#取得所有字串分割的結果
|
|
|
995 |
$result["spiltString"]=$result_spiltString;
|
|
|
996 |
|
|
|
997 |
#通過以上檢測,將執行狀態結果設爲 "true"
|
|
|
998 |
$result["status"]="true";
|
|
|
999 |
|
|
|
1000 |
#回傳結果
|
|
|
1001 |
return $result;
|
| 226 |
liveuser |
1002 |
|
| 3 |
liveuser |
1003 |
}#function spiltMutiString end
|
|
|
1004 |
|
|
|
1005 |
/*
|
|
|
1006 |
#函式說明:
|
|
|
1007 |
#將多行內容的字串,依行切割,切割的依據為"\r\n".
|
|
|
1008 |
#回傳結果:
|
|
|
1009 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗.
|
|
|
1010 |
#$result["error"],錯誤訊息陣列.
|
|
|
1011 |
#$result["function"],當前執行的函數名稱.#$result["oriStr"],要分割的原始字串內容.
|
|
|
1012 |
#$result["oriStr"],要分割的原始字串內容.
|
|
|
1013 |
#$result["dataArray"],爲以行分割好的字串陣列內容,$result["dataArray"][$i]爲第($i+1)行的內容.
|
|
|
1014 |
#$result["dataCounts"],爲總共分成幾行.
|
|
|
1015 |
#必填參數:
|
|
|
1016 |
#$conf["stringIn"],字串,要處理的多行文字字串.
|
|
|
1017 |
$conf["stringIn"]="";
|
|
|
1018 |
#可省略參數:
|
|
|
1019 |
#無.
|
|
|
1020 |
#參考資料:
|
|
|
1021 |
#http://dragonspring.pixnet.net/blog/post/33146613-%5blinux%5d%5btips%5d%e5%8e%bb%e9%99%a4dos%e6%aa%94%e6%a1%88%e8%a1%8c%e5%b0%be%e7%9a%84%5em => windows 與 linux 換行字元
|
|
|
1022 |
#備註:
|
|
|
1023 |
#無.
|
|
|
1024 |
*/
|
|
|
1025 |
public static function spiltMutiLineString(&$conf){
|
| 226 |
liveuser |
1026 |
|
| 3 |
liveuser |
1027 |
#初始化要回傳的內容
|
|
|
1028 |
$result=array();
|
|
|
1029 |
|
|
|
1030 |
#取得當前執行的函數名稱
|
|
|
1031 |
$result["function"]=__FUNCTION__;
|
|
|
1032 |
|
|
|
1033 |
#如果 $conf 不為陣列
|
|
|
1034 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1035 |
|
| 3 |
liveuser |
1036 |
#設置執行失敗
|
|
|
1037 |
$result["status"]="false";
|
| 226 |
liveuser |
1038 |
|
| 3 |
liveuser |
1039 |
#設置執行錯誤訊息
|
|
|
1040 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1041 |
|
|
|
1042 |
#如果傳入的參數為 null
|
|
|
1043 |
if($conf==null){
|
| 226 |
liveuser |
1044 |
|
| 3 |
liveuser |
1045 |
#設置執行錯誤訊息
|
|
|
1046 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1047 |
|
| 3 |
liveuser |
1048 |
}#if end
|
|
|
1049 |
|
|
|
1050 |
#回傳結果
|
|
|
1051 |
return $result;
|
| 226 |
liveuser |
1052 |
|
| 3 |
liveuser |
1053 |
}#if end
|
|
|
1054 |
|
|
|
1055 |
#檢查參數
|
|
|
1056 |
#函式說明:
|
|
|
1057 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1058 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1059 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1060 |
#$result["function"],當前執行的函式名稱.
|
|
|
1061 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1062 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1063 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1064 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1065 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1066 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1067 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1068 |
#必填寫的參數:
|
|
|
1069 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1070 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1071 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1072 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1073 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1074 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1075 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1076 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1077 |
#可以省略的參數:
|
|
|
1078 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1079 |
#$conf["canBeEmptyString"]="false";
|
|
|
1080 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1081 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
1082 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1083 |
#$conf["skipableVariableType"]=array();
|
|
|
1084 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1085 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1086 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1087 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1088 |
#參考資料來源:
|
|
|
1089 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1090 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1091 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1092 |
|
|
|
1093 |
#如果檢查有誤
|
|
|
1094 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1095 |
|
| 3 |
liveuser |
1096 |
#設置錯誤識別
|
|
|
1097 |
$result["status"]="false";
|
| 226 |
liveuser |
1098 |
|
| 3 |
liveuser |
1099 |
#設置錯誤訊息
|
|
|
1100 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1101 |
|
| 3 |
liveuser |
1102 |
#回傳結果
|
|
|
1103 |
return $result;
|
| 226 |
liveuser |
1104 |
|
| 3 |
liveuser |
1105 |
}#if end
|
| 226 |
liveuser |
1106 |
|
| 3 |
liveuser |
1107 |
#如果檢查不通過
|
|
|
1108 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1109 |
|
| 3 |
liveuser |
1110 |
#設置錯誤識別
|
|
|
1111 |
$result["status"]="false";
|
| 226 |
liveuser |
1112 |
|
| 3 |
liveuser |
1113 |
#設置錯誤訊息
|
|
|
1114 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1115 |
|
| 3 |
liveuser |
1116 |
#回傳結果
|
|
|
1117 |
return $result;
|
| 226 |
liveuser |
1118 |
|
| 3 |
liveuser |
1119 |
}#if end
|
| 226 |
liveuser |
1120 |
|
| 3 |
liveuser |
1121 |
#儲存要分割的原始字串內容
|
|
|
1122 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
1123 |
|
| 3 |
liveuser |
1124 |
#檢查多行文字是用\r\n還是\n來換行
|
|
|
1125 |
#函式說明:
|
|
|
1126 |
#檢查字串裡面有無指定的關鍵字
|
|
|
1127 |
#回傳結果:
|
|
|
1128 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1129 |
#$result["error"],錯誤訊息
|
|
|
1130 |
#$result["function"],當前執行的函數名稱.
|
|
|
1131 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
1132 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
1133 |
#必填參數:
|
|
|
1134 |
$conf["search::findKeyWord"]["keyWord"]="\r\n";#想要搜尋的關鍵字
|
|
|
1135 |
$conf["search::findKeyWord"]["string"]=$conf["stringIn"];#要被搜尋的字串內容
|
|
|
1136 |
#可省略參數:
|
|
|
1137 |
$conf["search::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
1138 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
1139 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
1140 |
|
| 3 |
liveuser |
1141 |
#如果檢查出錯
|
|
|
1142 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
1143 |
|
| 3 |
liveuser |
1144 |
#設置錯誤識別
|
|
|
1145 |
$result["status"]="false";
|
| 226 |
liveuser |
1146 |
|
| 3 |
liveuser |
1147 |
#設置錯誤訊息
|
|
|
1148 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
1149 |
|
| 3 |
liveuser |
1150 |
#回傳結果
|
|
|
1151 |
return $result;
|
| 226 |
liveuser |
1152 |
|
| 3 |
liveuser |
1153 |
}#if end
|
| 226 |
liveuser |
1154 |
|
| 3 |
liveuser |
1155 |
#預設換行的符號
|
|
|
1156 |
$spiltSymbol="\n";
|
| 226 |
liveuser |
1157 |
|
| 3 |
liveuser |
1158 |
#如果有找到關鍵字
|
|
|
1159 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
1160 |
|
| 3 |
liveuser |
1161 |
#更換換行的符號
|
|
|
1162 |
$spiltSymbol="\r\n";
|
| 226 |
liveuser |
1163 |
|
| 3 |
liveuser |
1164 |
}#if end
|
| 226 |
liveuser |
1165 |
|
| 3 |
liveuser |
1166 |
#函式說明:
|
|
|
1167 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1168 |
#回傳的參數:
|
|
|
1169 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1170 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1171 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1172 |
#必填參數:
|
|
|
1173 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["stringIn"];#要處理的字串。
|
|
|
1174 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=$spiltSymbol;#爲以哪個符號作爲分割
|
|
|
1175 |
$spiltString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
1176 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
1177 |
|
| 3 |
liveuser |
1178 |
#如果分割字串失敗
|
|
|
1179 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
1180 |
|
| 3 |
liveuser |
1181 |
#設置錯誤識別
|
|
|
1182 |
$result["status"]="false";
|
| 226 |
liveuser |
1183 |
|
| 3 |
liveuser |
1184 |
#設置錯誤訊息
|
|
|
1185 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1186 |
|
| 3 |
liveuser |
1187 |
#回傳結果
|
|
|
1188 |
return $result;
|
| 226 |
liveuser |
1189 |
|
| 3 |
liveuser |
1190 |
}#if end
|
| 226 |
liveuser |
1191 |
|
| 3 |
liveuser |
1192 |
#儲存每一行的內容
|
|
|
1193 |
$result["dataArray"]=$spiltString["dataArray"];
|
| 226 |
liveuser |
1194 |
|
| 3 |
liveuser |
1195 |
#取得分成幾行
|
|
|
1196 |
$result["dataCounts"]=$spiltString["dataCounts"];
|
| 226 |
liveuser |
1197 |
|
| 3 |
liveuser |
1198 |
#執行到這邊,代表執行成功
|
|
|
1199 |
$result["status"]="true";
|
| 226 |
liveuser |
1200 |
|
| 3 |
liveuser |
1201 |
#回傳每行的內容
|
|
|
1202 |
return $result;
|
| 226 |
liveuser |
1203 |
|
| 3 |
liveuser |
1204 |
}#funcrion spiltMutiLineString end
|
|
|
1205 |
|
|
|
1206 |
/*
|
|
|
1207 |
#函式說明:
|
|
|
1208 |
#將一字串的前幾個文字轉爲ACSII並存到陣列裏面
|
|
|
1209 |
#回傳結果:
|
|
|
1210 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
1211 |
#$result["error"],錯誤訊息陣列.
|
|
|
1212 |
#$result["function"],當前執行的函數名稱.
|
|
|
1213 |
#$result["dataCounts"],爲總共有幾個字轉好的ASCII陣列。
|
|
|
1214 |
#$result["acsiiArray"],爲每個字轉好的ASCII陣列內容,$result["acsiiArray"][$i]爲第 $i+1 個字的ACSII內容。
|
|
|
1215 |
#必填參數:
|
|
|
1216 |
#$conf["stringIn"],字串,爲要處理的字串.
|
|
|
1217 |
$conf["stringIn"]="";
|
|
|
1218 |
#可省略參數:
|
|
|
1219 |
#$conf["wordsLong"],字串,爲要取得前幾個字元,若沒有要限定則可以不設定內容。
|
|
|
1220 |
#$conf["wordsLong"]="";
|
|
|
1221 |
#參考資料:
|
|
|
1222 |
#無.
|
|
|
1223 |
#備註:
|
|
|
1224 |
#無.
|
| 226 |
liveuser |
1225 |
*/
|
| 3 |
liveuser |
1226 |
function StringToASCII(&$conf){
|
|
|
1227 |
|
|
|
1228 |
#初始化要回傳的內容
|
|
|
1229 |
$result=array();
|
|
|
1230 |
|
|
|
1231 |
#取得當前執行的函數名稱
|
|
|
1232 |
$result["function"]=__FUNCTION__;
|
|
|
1233 |
|
|
|
1234 |
#如果 $conf 不為陣列
|
|
|
1235 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1236 |
|
| 3 |
liveuser |
1237 |
#設置執行失敗
|
|
|
1238 |
$result["status"]="false";
|
| 226 |
liveuser |
1239 |
|
| 3 |
liveuser |
1240 |
#設置執行錯誤訊息
|
|
|
1241 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1242 |
|
|
|
1243 |
#回傳結果
|
|
|
1244 |
return $result;
|
| 226 |
liveuser |
1245 |
|
| 3 |
liveuser |
1246 |
}#if end
|
|
|
1247 |
|
|
|
1248 |
#檢查參數
|
|
|
1249 |
#函式說明:
|
|
|
1250 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1251 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1252 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1253 |
#$result["function"],當前執行的函式名稱.
|
|
|
1254 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1255 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1256 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1257 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1258 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1259 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1260 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1261 |
#必填寫的參數:
|
|
|
1262 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1263 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1264 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1265 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1266 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1267 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1268 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1269 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1270 |
#可以省略的參數:
|
|
|
1271 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1272 |
#$conf["canBeEmptyString"]="false";
|
|
|
1273 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1274 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wordsLong");
|
| 226 |
liveuser |
1275 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1276 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1277 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1278 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
1279 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1280 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1281 |
#參考資料來源:
|
|
|
1282 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1283 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1284 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1285 |
|
|
|
1286 |
#如果檢查有誤
|
|
|
1287 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1288 |
|
| 3 |
liveuser |
1289 |
#設置錯誤識別
|
|
|
1290 |
$result["status"]="false";
|
| 226 |
liveuser |
1291 |
|
| 3 |
liveuser |
1292 |
#設置錯誤訊息
|
|
|
1293 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1294 |
|
| 3 |
liveuser |
1295 |
#回傳結果
|
|
|
1296 |
return $result;
|
| 226 |
liveuser |
1297 |
|
| 3 |
liveuser |
1298 |
}#if end
|
| 226 |
liveuser |
1299 |
|
| 3 |
liveuser |
1300 |
#如果檢查不通過
|
|
|
1301 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1302 |
|
| 3 |
liveuser |
1303 |
#設置錯誤識別
|
|
|
1304 |
$result["status"]="false";
|
| 226 |
liveuser |
1305 |
|
| 3 |
liveuser |
1306 |
#設置錯誤訊息
|
|
|
1307 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1308 |
|
| 3 |
liveuser |
1309 |
#回傳結果
|
|
|
1310 |
return $result;
|
| 226 |
liveuser |
1311 |
|
| 3 |
liveuser |
1312 |
}#if end
|
|
|
1313 |
|
| 226 |
liveuser |
1314 |
#將 $string 分割成一個個字元,並存到陣列 #stringCharArray
|
|
|
1315 |
$stringCharArray=str_split($conf["stringIn"]);
|
| 3 |
liveuser |
1316 |
|
|
|
1317 |
#取得分割成幾個字元
|
|
|
1318 |
$stringCharArrayCounts=count($stringCharArray);
|
|
|
1319 |
|
|
|
1320 |
#如果沒有限定要前面幾個字則將全部都轉成ASCII
|
|
|
1321 |
if(!isset($conf["wordsLong"])){
|
| 226 |
liveuser |
1322 |
|
| 3 |
liveuser |
1323 |
$conf["wordsLong"]=$stringCharArrayCounts;
|
| 226 |
liveuser |
1324 |
|
| 3 |
liveuser |
1325 |
}#if end
|
|
|
1326 |
|
|
|
1327 |
#將前面 $wordsLong 個字轉換成ASCII並存到 $charASCII 陣列裏面
|
|
|
1328 |
for($i=0;$i<$conf["wordsLong"];$i++){
|
| 226 |
liveuser |
1329 |
|
|
|
1330 |
$charASCII[$i]=ord($stringCharArray[$i]);
|
|
|
1331 |
|
| 3 |
liveuser |
1332 |
}#for end
|
| 226 |
liveuser |
1333 |
|
| 3 |
liveuser |
1334 |
#取得總共有幾個字的ACSII
|
|
|
1335 |
$result["dataCounts"]=count($charASCII);
|
|
|
1336 |
|
|
|
1337 |
#取得每個字轉好的ACSII陣列
|
|
|
1338 |
$result["acsiiArray"]=$charASCII;
|
|
|
1339 |
|
|
|
1340 |
#設置執行正常
|
|
|
1341 |
$result["status"]="true";
|
|
|
1342 |
|
|
|
1343 |
#回傳結果
|
| 226 |
liveuser |
1344 |
return $result;
|
|
|
1345 |
|
| 3 |
liveuser |
1346 |
}#function StringToASCII end
|
|
|
1347 |
|
|
|
1348 |
/*
|
|
|
1349 |
#函式說明:
|
|
|
1350 |
#將數字字串轉換成實際的數字
|
|
|
1351 |
#回傳結果:
|
|
|
1352 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
1353 |
#$result["error"],錯誤訊息陣列.
|
|
|
1354 |
#$result["function"],當前執行的函數名稱.
|
|
|
1355 |
#$result["content"],實際的數字.
|
|
|
1356 |
#$result["ori"],未轉換的內容.
|
|
|
1357 |
#必填參數:
|
|
|
1358 |
#$conf["stringIn"],字串,要處理度數字字串。
|
|
|
1359 |
$conf["stringIn"]="";
|
|
|
1360 |
#可省略參數:
|
|
|
1361 |
#無.
|
|
|
1362 |
#參考資料:
|
|
|
1363 |
#http://www.phpf1.com/tutorial/php-string-to-int.html
|
|
|
1364 |
#備註:
|
|
|
1365 |
#無.
|
|
|
1366 |
*/
|
|
|
1367 |
public static function stringIntToInt(&$conf){
|
|
|
1368 |
|
|
|
1369 |
#初始化要回傳的內容
|
|
|
1370 |
$result=array();
|
|
|
1371 |
|
|
|
1372 |
#取得當前執行的函數名稱
|
|
|
1373 |
$result["function"]=__FUNCTION__;
|
|
|
1374 |
|
|
|
1375 |
#如果 $conf 不為陣列
|
|
|
1376 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1377 |
|
| 3 |
liveuser |
1378 |
#設置執行失敗
|
|
|
1379 |
$result["status"]="false";
|
| 226 |
liveuser |
1380 |
|
| 3 |
liveuser |
1381 |
#設置執行錯誤訊息
|
|
|
1382 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1383 |
|
|
|
1384 |
#如果傳入的參數為 null
|
|
|
1385 |
if($conf==null){
|
| 226 |
liveuser |
1386 |
|
| 3 |
liveuser |
1387 |
#設置執行錯誤訊息
|
|
|
1388 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1389 |
|
| 3 |
liveuser |
1390 |
}#if end
|
|
|
1391 |
|
|
|
1392 |
#回傳結果
|
|
|
1393 |
return $result;
|
| 226 |
liveuser |
1394 |
|
| 3 |
liveuser |
1395 |
}#if end
|
|
|
1396 |
|
|
|
1397 |
#檢查參數
|
|
|
1398 |
#函式說明:
|
|
|
1399 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1400 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1401 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1402 |
#$result["function"],當前執行的函式名稱.
|
|
|
1403 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1404 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1405 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1406 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1407 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1408 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1409 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1410 |
#必填寫的參數:
|
|
|
1411 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1412 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1413 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1414 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1415 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1416 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1417 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1418 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1419 |
#可以省略的參數:
|
|
|
1420 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1421 |
#$conf["canBeEmptyString"]="false";
|
|
|
1422 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1423 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
1424 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1425 |
#$conf["skipableVariableType"]=array();
|
|
|
1426 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1427 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1428 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1429 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1430 |
#參考資料來源:
|
|
|
1431 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1432 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1433 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1434 |
|
|
|
1435 |
#如果檢查有誤
|
|
|
1436 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1437 |
|
| 3 |
liveuser |
1438 |
#設置錯誤識別
|
|
|
1439 |
$result["status"]="false";
|
| 226 |
liveuser |
1440 |
|
| 3 |
liveuser |
1441 |
#設置錯誤訊息
|
|
|
1442 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1443 |
|
| 3 |
liveuser |
1444 |
#回傳結果
|
|
|
1445 |
return $result;
|
| 226 |
liveuser |
1446 |
|
| 3 |
liveuser |
1447 |
}#if end
|
| 226 |
liveuser |
1448 |
|
| 3 |
liveuser |
1449 |
#如果檢查不通過
|
|
|
1450 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1451 |
|
| 3 |
liveuser |
1452 |
#設置錯誤識別
|
|
|
1453 |
$result["status"]="false";
|
| 226 |
liveuser |
1454 |
|
| 3 |
liveuser |
1455 |
#設置錯誤訊息
|
|
|
1456 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1457 |
|
| 3 |
liveuser |
1458 |
#回傳結果
|
|
|
1459 |
return $result;
|
| 226 |
liveuser |
1460 |
|
| 3 |
liveuser |
1461 |
}#if end
|
| 226 |
liveuser |
1462 |
|
| 3 |
liveuser |
1463 |
#取得原始的內容
|
|
|
1464 |
$result["ori"]=$conf["stringIn"];
|
|
|
1465 |
|
|
|
1466 |
#取得轉換好的數字
|
|
|
1467 |
$result["content"]=(int)$conf["stringIn"];
|
|
|
1468 |
|
|
|
1469 |
#設置執行正常
|
|
|
1470 |
$result["status"]="true";
|
|
|
1471 |
|
|
|
1472 |
#回傳結果
|
|
|
1473 |
return $result;
|
| 226 |
liveuser |
1474 |
|
| 3 |
liveuser |
1475 |
}#function stringIntToInt end
|
|
|
1476 |
|
|
|
1477 |
/*
|
|
|
1478 |
#函式說明:
|
| 218 |
liveuser |
1479 |
#將字串中的特定內容取代.
|
|
|
1480 |
#回傳結果:
|
|
|
1481 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1482 |
#$result["function"],當前執行的函數.
|
|
|
1483 |
#$result["content"],爲處理好的字串.
|
|
|
1484 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
1485 |
#$result["argu"],使用的參數.
|
| 218 |
liveuser |
1486 |
#必填參數:
|
|
|
1487 |
#$conf["stringIn"],字串,爲要處理的字串
|
|
|
1488 |
$conf["stringIn"]="";
|
|
|
1489 |
#$conf["selectedCharacter"],字串,爲被選擇要處理的字串/字元,\n」代表換行,「\t」代表tab鍵的間隔.
|
|
|
1490 |
$conf["selectedCharacter"]="";
|
|
|
1491 |
#$conf["changeTo"],字串,爲被選擇的字元要換成什麼字串/字元.
|
|
|
1492 |
$conf["changeTo"]="";
|
|
|
1493 |
#參考資料:
|
|
|
1494 |
#無.
|
|
|
1495 |
#備註:
|
|
|
1496 |
#無.
|
|
|
1497 |
*/
|
|
|
1498 |
public static function replaceOnce(&$conf){
|
| 226 |
liveuser |
1499 |
|
| 218 |
liveuser |
1500 |
#初始化要回傳的結果
|
|
|
1501 |
$result=array();
|
| 226 |
liveuser |
1502 |
|
| 218 |
liveuser |
1503 |
#設置當前執行函數
|
|
|
1504 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1505 |
|
| 218 |
liveuser |
1506 |
#初始化要回傳的主要內容
|
|
|
1507 |
$result["content"]="";
|
|
|
1508 |
|
|
|
1509 |
#如果 $conf 不為陣列
|
|
|
1510 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1511 |
|
| 218 |
liveuser |
1512 |
#設置執行失敗
|
|
|
1513 |
$result["status"]="false";
|
| 226 |
liveuser |
1514 |
|
| 218 |
liveuser |
1515 |
#設置執行錯誤訊息
|
|
|
1516 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1517 |
|
|
|
1518 |
#如果傳入的參數為 null
|
|
|
1519 |
if($conf==null){
|
| 226 |
liveuser |
1520 |
|
| 218 |
liveuser |
1521 |
#設置執行錯誤訊息
|
|
|
1522 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1523 |
|
| 218 |
liveuser |
1524 |
}#if end
|
|
|
1525 |
|
|
|
1526 |
#回傳結果
|
|
|
1527 |
return $result;
|
| 226 |
liveuser |
1528 |
|
| 218 |
liveuser |
1529 |
}#if end
|
|
|
1530 |
|
| 226 |
liveuser |
1531 |
#取得參數
|
| 218 |
liveuser |
1532 |
$result["argu"]=$conf;
|
|
|
1533 |
|
|
|
1534 |
#函式說明:
|
|
|
1535 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1536 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1537 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1538 |
#$result["function"],當前執行的函式名稱.
|
|
|
1539 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1540 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1541 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1542 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1543 |
#必填寫的參數:
|
|
|
1544 |
#$conf["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
1545 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
1546 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1547 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("stringIn","selectedCharacter","changeTo");
|
| 226 |
liveuser |
1548 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 218 |
liveuser |
1549 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1550 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1551 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
1552 |
#可以省略的參數:
|
|
|
1553 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
1554 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
1555 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些變數不可以為空字串或集合.
|
|
|
1556 |
#$conf["variableCheck.checkArguments"]["skipableVariableCanNotBeEmpty"]=array("");
|
|
|
1557 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1558 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("selectedCharacter","changeTo");
|
| 226 |
liveuser |
1559 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 218 |
liveuser |
1560 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
1561 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
1562 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(array("<",">","=","//","'","$","%","&","|","/*","*/","#","\""),null);
|
|
|
1563 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
1564 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
1565 |
|
| 218 |
liveuser |
1566 |
#如果檢查失敗
|
|
|
1567 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1568 |
|
| 218 |
liveuser |
1569 |
#設置執行失敗
|
|
|
1570 |
$result["status"]="false";
|
| 226 |
liveuser |
1571 |
|
| 218 |
liveuser |
1572 |
#設置錯誤訊息
|
|
|
1573 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1574 |
|
| 218 |
liveuser |
1575 |
#回傳結果
|
|
|
1576 |
return $result;
|
| 226 |
liveuser |
1577 |
|
| 218 |
liveuser |
1578 |
}#if end
|
| 226 |
liveuser |
1579 |
|
| 218 |
liveuser |
1580 |
#如果檢查不通過
|
|
|
1581 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1582 |
|
| 218 |
liveuser |
1583 |
#設置執行失敗
|
|
|
1584 |
$result["status"]="false";
|
| 226 |
liveuser |
1585 |
|
| 218 |
liveuser |
1586 |
#設置錯誤訊息
|
|
|
1587 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1588 |
|
| 218 |
liveuser |
1589 |
#回傳結果
|
|
|
1590 |
return $result;
|
| 226 |
liveuser |
1591 |
|
| 218 |
liveuser |
1592 |
}#if end
|
| 226 |
liveuser |
1593 |
|
| 218 |
liveuser |
1594 |
#只取代一次
|
|
|
1595 |
$one=1;
|
| 226 |
liveuser |
1596 |
|
| 218 |
liveuser |
1597 |
#取得進行替換後的結果
|
|
|
1598 |
$result["content"]=str_replace($conf["selectedCharacter"],$conf["changeTo"],$conf["stringIn"],$one);
|
|
|
1599 |
|
|
|
1600 |
#檢查變數內容
|
|
|
1601 |
$result["status"]="true";
|
| 226 |
liveuser |
1602 |
|
| 218 |
liveuser |
1603 |
#回傳經過整理的字串
|
|
|
1604 |
return $result;
|
| 226 |
liveuser |
1605 |
|
| 218 |
liveuser |
1606 |
}#function replaceOnce end
|
|
|
1607 |
|
|
|
1608 |
/*
|
|
|
1609 |
#函式說明:
|
| 3 |
liveuser |
1610 |
#處理字串避免網頁出錯
|
|
|
1611 |
#回傳結果:
|
|
|
1612 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1613 |
#$result["function"],當前執行的函數.
|
|
|
1614 |
#$result["content"],爲處理好的字串.
|
|
|
1615 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
1616 |
#$result["argu"],使用的參數.
|
| 3 |
liveuser |
1617 |
#必填參數:
|
|
|
1618 |
#$conf["stringIn"],字串,爲要處理的字串
|
|
|
1619 |
$conf["stringIn"]="";
|
|
|
1620 |
#可省略參數:
|
|
|
1621 |
#$conf["selectedCharacter"],字串陣列,爲被選擇要處理的字串/字元,須爲陣列值。若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1622 |
#$conf["selectedCharacter"]=array("");
|
|
|
1623 |
#$conf["changeTo"],字串陣列,爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1624 |
#$conf["changeTo"]=array("");
|
|
|
1625 |
#參考資料:
|
|
|
1626 |
#無.
|
|
|
1627 |
#備註:
|
|
|
1628 |
#無.
|
| 226 |
liveuser |
1629 |
*/
|
| 3 |
liveuser |
1630 |
public static function correctCharacter(&$conf){
|
|
|
1631 |
|
|
|
1632 |
#初始化要回傳的結果
|
|
|
1633 |
$result=array();
|
| 226 |
liveuser |
1634 |
|
| 3 |
liveuser |
1635 |
#設置當前執行函數
|
| 218 |
liveuser |
1636 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1637 |
|
| 3 |
liveuser |
1638 |
#初始化要回傳的主要內容
|
|
|
1639 |
$result["content"]="";
|
|
|
1640 |
|
|
|
1641 |
#如果 $conf 不為陣列
|
|
|
1642 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1643 |
|
| 3 |
liveuser |
1644 |
#設置執行失敗
|
|
|
1645 |
$result["status"]="false";
|
| 226 |
liveuser |
1646 |
|
| 3 |
liveuser |
1647 |
#設置執行錯誤訊息
|
|
|
1648 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1649 |
|
|
|
1650 |
#如果傳入的參數為 null
|
|
|
1651 |
if($conf==null){
|
| 226 |
liveuser |
1652 |
|
| 3 |
liveuser |
1653 |
#設置執行錯誤訊息
|
|
|
1654 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1655 |
|
| 3 |
liveuser |
1656 |
}#if end
|
|
|
1657 |
|
|
|
1658 |
#回傳結果
|
|
|
1659 |
return $result;
|
| 226 |
liveuser |
1660 |
|
| 3 |
liveuser |
1661 |
}#if end
|
|
|
1662 |
|
| 226 |
liveuser |
1663 |
#取得參數
|
| 218 |
liveuser |
1664 |
$result["argu"]=$conf;
|
| 3 |
liveuser |
1665 |
|
|
|
1666 |
#函式說明:
|
|
|
1667 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1668 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1669 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1670 |
#$result["function"],當前執行的函式名稱.
|
|
|
1671 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1672 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1673 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1674 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1675 |
#必填寫的參數:
|
|
|
1676 |
#$conf["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
1677 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
1678 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1679 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1680 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1681 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1682 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1683 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
| 218 |
liveuser |
1684 |
#可以省略的參數:
|
| 3 |
liveuser |
1685 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
1686 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
1687 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些變數不可以為空字串或集合.
|
|
|
1688 |
$conf["variableCheck.checkArguments"]["skipableVariableCanNotBeEmpty"]=array("selectedCharacter");
|
|
|
1689 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1690 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("selectedCharacter","changeTo");
|
| 226 |
liveuser |
1691 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1692 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
1693 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
1694 |
$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(array("<",">","=","//","'","$","%","&","|","/*","*/","#","\""),null);
|
|
|
1695 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
1696 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
1697 |
|
| 3 |
liveuser |
1698 |
#如果檢查失敗
|
|
|
1699 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1700 |
|
| 3 |
liveuser |
1701 |
#設置執行失敗
|
|
|
1702 |
$result["status"]="false";
|
| 226 |
liveuser |
1703 |
|
| 3 |
liveuser |
1704 |
#設置錯誤訊息
|
|
|
1705 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1706 |
|
| 3 |
liveuser |
1707 |
#回傳結果
|
|
|
1708 |
return $result;
|
| 226 |
liveuser |
1709 |
|
| 3 |
liveuser |
1710 |
}#if end
|
| 226 |
liveuser |
1711 |
|
| 3 |
liveuser |
1712 |
#如果檢查不通過
|
|
|
1713 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1714 |
|
| 3 |
liveuser |
1715 |
#設置執行失敗
|
|
|
1716 |
$result["status"]="false";
|
| 226 |
liveuser |
1717 |
|
| 3 |
liveuser |
1718 |
#設置錯誤訊息
|
|
|
1719 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1720 |
|
| 3 |
liveuser |
1721 |
#回傳結果
|
|
|
1722 |
return $result;
|
| 226 |
liveuser |
1723 |
|
| 218 |
liveuser |
1724 |
}#if end
|
| 3 |
liveuser |
1725 |
|
|
|
1726 |
#取得有幾種字串要處理
|
|
|
1727 |
$num=count($conf["selectedCharacter"]);
|
|
|
1728 |
|
|
|
1729 |
#如果 $conf["changeTo"] 有設定
|
|
|
1730 |
if(isset($conf["changeTo"])){
|
| 226 |
liveuser |
1731 |
|
| 3 |
liveuser |
1732 |
#如果 count($conf["selectedCharacter"]) 與 count($conf["changeTo"]) 不相等
|
|
|
1733 |
if(count($conf["selectedCharacter"])!=count($conf["changeTo"])){
|
| 226 |
liveuser |
1734 |
|
| 3 |
liveuser |
1735 |
#設置執行失敗
|
|
|
1736 |
$result["status"]="false";
|
| 226 |
liveuser |
1737 |
|
| 3 |
liveuser |
1738 |
#設置錯誤訊息
|
|
|
1739 |
$result["error"][]="\$conf[\"selectedCharacter\"] 與 \$conf[\"changeTo\"] 的元素數量不相等!";
|
| 226 |
liveuser |
1740 |
|
| 3 |
liveuser |
1741 |
#回傳結果
|
|
|
1742 |
return $result;
|
| 226 |
liveuser |
1743 |
|
| 3 |
liveuser |
1744 |
}#if end
|
| 226 |
liveuser |
1745 |
|
| 3 |
liveuser |
1746 |
}#if end
|
|
|
1747 |
|
|
|
1748 |
#如果 $conf["changeTo"] 爲空,則將每個要處理的字串,替換成""。
|
|
|
1749 |
if(!isset($conf["changeTo"])){
|
|
|
1750 |
|
|
|
1751 |
#有幾種要處理的字元就放進去幾個要對照替換的字串。
|
|
|
1752 |
for($i=0;$i<$num;$i++){
|
| 226 |
liveuser |
1753 |
|
| 3 |
liveuser |
1754 |
$conf["changeTo"][$i]="";
|
|
|
1755 |
|
|
|
1756 |
}#for end
|
|
|
1757 |
|
|
|
1758 |
}#if end
|
|
|
1759 |
|
|
|
1760 |
#處理 $num 次
|
|
|
1761 |
for($i=0;$i<$num;$i++){
|
|
|
1762 |
|
|
|
1763 |
#如果要處理的字元為空字串
|
|
|
1764 |
if($conf["selectedCharacter"][$i]==""){
|
| 226 |
liveuser |
1765 |
|
| 3 |
liveuser |
1766 |
#debug
|
|
|
1767 |
#echo "<p>空字串不處理</p>";
|
| 226 |
liveuser |
1768 |
|
| 3 |
liveuser |
1769 |
#跳過該此處理
|
|
|
1770 |
continue;
|
| 226 |
liveuser |
1771 |
|
| 3 |
liveuser |
1772 |
}#if end
|
|
|
1773 |
|
|
|
1774 |
#進行轉換
|
|
|
1775 |
$conf["stringIn"] = str_replace($conf["selectedCharacter"][$i],$conf["changeTo"][$i],$conf["stringIn"]);
|
|
|
1776 |
|
|
|
1777 |
}#for end
|
|
|
1778 |
|
|
|
1779 |
#取得處理好的結果
|
|
|
1780 |
$result["content"]=$conf["stringIn"];
|
|
|
1781 |
|
|
|
1782 |
#檢查變數內容
|
|
|
1783 |
$result["status"]="true";
|
| 226 |
liveuser |
1784 |
|
| 3 |
liveuser |
1785 |
#回傳經過整理的字串
|
|
|
1786 |
return $result;
|
|
|
1787 |
|
|
|
1788 |
}#function correctCharacter end
|
| 226 |
liveuser |
1789 |
|
| 3 |
liveuser |
1790 |
/*
|
|
|
1791 |
#函式說明:
|
|
|
1792 |
#處理多個字串避免網頁出錯
|
|
|
1793 |
#回傳結果:
|
|
|
1794 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗.
|
|
|
1795 |
#$result["function"],當前執行的函數.
|
|
|
1796 |
#$result["error"],錯誤訊息.
|
|
|
1797 |
#$result["processedStrArray"],處理好的字串陣列.
|
|
|
1798 |
#必填參數:
|
|
|
1799 |
#$conf["stringIn"],字串陣列,爲要處理的字串陣列.
|
|
|
1800 |
#$conf["stringIn"]=array("");
|
|
|
1801 |
#可省略參數:
|
|
|
1802 |
#$conf["selectedCharacter"],字串陣列,爲被選擇要處理的字串/字元,須爲陣列值。若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
| 226 |
liveuser |
1803 |
#$conf["selectedCharacter"]=array("");
|
| 3 |
liveuser |
1804 |
#$conf["changeTo"],字串陣列,爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1805 |
#$conf["changeTo"]=array();
|
|
|
1806 |
#參考資料:
|
|
|
1807 |
#無.
|
|
|
1808 |
#備註:
|
|
|
1809 |
#無.
|
| 226 |
liveuser |
1810 |
*/
|
| 3 |
liveuser |
1811 |
public static function correctMutiStrCharacter(&$conf){
|
| 226 |
liveuser |
1812 |
|
| 3 |
liveuser |
1813 |
#初始化要回傳的結果
|
|
|
1814 |
$result=array();
|
| 226 |
liveuser |
1815 |
|
| 3 |
liveuser |
1816 |
#設置當前執行函數
|
| 226 |
liveuser |
1817 |
$result["function"]=__FUNCTION__;
|
|
|
1818 |
|
| 3 |
liveuser |
1819 |
#初始化要回傳的主要內容
|
|
|
1820 |
$result["content"]="";
|
|
|
1821 |
|
|
|
1822 |
#如果 $conf 不為陣列
|
|
|
1823 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1824 |
|
| 3 |
liveuser |
1825 |
#設置執行失敗
|
|
|
1826 |
$result["status"]="false";
|
| 226 |
liveuser |
1827 |
|
| 3 |
liveuser |
1828 |
#設置執行錯誤訊息
|
|
|
1829 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1830 |
|
|
|
1831 |
#如果傳入的參數為 null
|
|
|
1832 |
if($conf==null){
|
| 226 |
liveuser |
1833 |
|
| 3 |
liveuser |
1834 |
#設置執行錯誤訊息
|
|
|
1835 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1836 |
|
| 3 |
liveuser |
1837 |
}#if end
|
|
|
1838 |
|
|
|
1839 |
#回傳結果
|
|
|
1840 |
return $result;
|
| 226 |
liveuser |
1841 |
|
|
|
1842 |
}#if end
|
|
|
1843 |
|
| 3 |
liveuser |
1844 |
#檢查參數
|
|
|
1845 |
#函式說明:
|
|
|
1846 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1847 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1848 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1849 |
#$result["function"],當前執行的函式名稱.
|
|
|
1850 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1851 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1852 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1853 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1854 |
#必填寫的參數:
|
|
|
1855 |
#$conf["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
1856 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
1857 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1858 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1859 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1860 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
1861 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1862 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
1863 |
#可以省略的參數:
|
|
|
1864 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
1865 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
1866 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1867 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("selectedCharacter","changeTo");
|
| 226 |
liveuser |
1868 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1869 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
1870 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
1871 |
$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
1872 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
1873 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
1874 |
|
| 3 |
liveuser |
1875 |
#如果檢查失敗
|
|
|
1876 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1877 |
|
| 3 |
liveuser |
1878 |
#設置執行失敗
|
|
|
1879 |
$result["status"]="false";
|
| 226 |
liveuser |
1880 |
|
| 3 |
liveuser |
1881 |
#設置錯誤訊息
|
|
|
1882 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1883 |
|
| 3 |
liveuser |
1884 |
#回傳結果
|
|
|
1885 |
return $result;
|
| 226 |
liveuser |
1886 |
|
| 3 |
liveuser |
1887 |
}#if end
|
| 226 |
liveuser |
1888 |
|
| 3 |
liveuser |
1889 |
#如果檢查不通過
|
|
|
1890 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1891 |
|
| 3 |
liveuser |
1892 |
#設置執行失敗
|
|
|
1893 |
$result["status"]="false";
|
| 226 |
liveuser |
1894 |
|
| 3 |
liveuser |
1895 |
#設置錯誤訊息
|
|
|
1896 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1897 |
|
| 3 |
liveuser |
1898 |
#回傳結果
|
|
|
1899 |
return $result;
|
| 226 |
liveuser |
1900 |
|
|
|
1901 |
}#if end
|
|
|
1902 |
|
| 3 |
liveuser |
1903 |
#針對每個 $unProcessedStr 的元素執行一次
|
|
|
1904 |
foreach($conf["stringIn"] as $unProcessedStrKey=>$unProcessedStrValue){
|
| 226 |
liveuser |
1905 |
|
| 3 |
liveuser |
1906 |
#如果該行為 ""
|
|
|
1907 |
if($unProcessedStrValue===""){
|
| 226 |
liveuser |
1908 |
|
| 3 |
liveuser |
1909 |
#不處理直接儲存成 ""
|
|
|
1910 |
$result["processedStrArray"][$unProcessedStrKey]="";
|
| 226 |
liveuser |
1911 |
|
| 3 |
liveuser |
1912 |
#跳過該回合
|
|
|
1913 |
continue;
|
| 226 |
liveuser |
1914 |
|
| 3 |
liveuser |
1915 |
}#if end
|
| 226 |
liveuser |
1916 |
|
| 3 |
liveuser |
1917 |
#函式說明:
|
|
|
1918 |
#處理字串避免網頁出錯
|
|
|
1919 |
#回傳結果:
|
|
|
1920 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1921 |
#$result["content"],爲處理好的字串。
|
|
|
1922 |
#$result["error"],錯誤訊息陣列
|
|
|
1923 |
#必填參數:
|
|
|
1924 |
$conf["variableCheck.correctCharacter"]["stringIn"]=$unProcessedStrValue;#爲要處理的字串
|
|
|
1925 |
#可省略參數:
|
| 226 |
liveuser |
1926 |
|
| 3 |
liveuser |
1927 |
#如果 $conf["selectedCharacter"] 有設定
|
|
|
1928 |
if(isset($conf["selectedCharacter"])){
|
| 226 |
liveuser |
1929 |
|
| 3 |
liveuser |
1930 |
$conf["variableCheck.correctCharacter"]["selectedCharacter"]=$conf["selectedCharacter"];#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1931 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
1932 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
| 226 |
liveuser |
1933 |
|
| 3 |
liveuser |
1934 |
}#if end
|
| 226 |
liveuser |
1935 |
|
| 3 |
liveuser |
1936 |
#如果 $conf["changeTo"] 有設定
|
|
|
1937 |
if(isset($conf["changeTo"])){
|
| 226 |
liveuser |
1938 |
|
| 3 |
liveuser |
1939 |
$conf["variableCheck.correctCharacter"]["changeTo"]=$conf["changeTo"];#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
| 226 |
liveuser |
1940 |
|
|
|
1941 |
}#if end
|
|
|
1942 |
|
| 3 |
liveuser |
1943 |
$processedStrResult=stringProcess::correctCharacter($conf["variableCheck.correctCharacter"]);
|
| 226 |
liveuser |
1944 |
unset($conf["variableCheck.correctCharacter"]);
|
|
|
1945 |
|
|
|
1946 |
#如果 $processedStrResult["status"] 等於 "false"
|
| 3 |
liveuser |
1947 |
if($processedStrResult["status"]=="false"){
|
| 226 |
liveuser |
1948 |
|
| 3 |
liveuser |
1949 |
#設置錯誤
|
|
|
1950 |
$result["status"]="false";
|
| 226 |
liveuser |
1951 |
|
| 3 |
liveuser |
1952 |
#設置錯誤訊息
|
|
|
1953 |
$result["error"]=$processedStrResult;
|
| 226 |
liveuser |
1954 |
|
| 3 |
liveuser |
1955 |
#回傳結果
|
|
|
1956 |
return $result;
|
| 226 |
liveuser |
1957 |
|
| 3 |
liveuser |
1958 |
}#if end
|
| 226 |
liveuser |
1959 |
|
| 3 |
liveuser |
1960 |
#取得處理好的字串
|
|
|
1961 |
$result["processedStrArray"][$unProcessedStrKey]=$processedStrResult["content"];
|
| 226 |
liveuser |
1962 |
|
| 3 |
liveuser |
1963 |
}#foreach end
|
| 226 |
liveuser |
1964 |
|
| 3 |
liveuser |
1965 |
#執行到這邊代表執行成功
|
|
|
1966 |
$result["status"]="true";
|
| 226 |
liveuser |
1967 |
|
| 3 |
liveuser |
1968 |
#回傳結果
|
|
|
1969 |
return $result;
|
| 226 |
liveuser |
1970 |
|
| 3 |
liveuser |
1971 |
}#function correctMutiStrCharacter end
|
|
|
1972 |
|
|
|
1973 |
/*
|
|
|
1974 |
#函式說明:
|
|
|
1975 |
#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
|
|
|
1976 |
#回傳結果:
|
|
|
1977 |
#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1978 |
#$result["function"],當前執行的函數.
|
|
|
1979 |
#$result["error"],錯誤訊息陣列.
|
|
|
1980 |
#$result["argu"],使用者參數.
|
|
|
1981 |
#$result["changedPath"],處理完後回傳的目錄字串.
|
|
|
1982 |
#$result["oriPath"],原始的路徑字串
|
|
|
1983 |
#必填參數:
|
|
|
1984 |
#$conf["dirStr"],字串,要處理的檔案目錄字串.
|
|
|
1985 |
$conf["dirStr"]="";
|
|
|
1986 |
#可省略參數:
|
|
|
1987 |
#無.
|
|
|
1988 |
#參考資料:
|
|
|
1989 |
#無.
|
|
|
1990 |
#備註:
|
|
|
1991 |
#考慮用realpath取代
|
|
|
1992 |
*/
|
|
|
1993 |
public static function changeDirByDotDotSolidus(&$conf){
|
| 226 |
liveuser |
1994 |
|
| 3 |
liveuser |
1995 |
#初始化要回傳的內容
|
|
|
1996 |
$result=array();
|
|
|
1997 |
|
|
|
1998 |
#取得當前執行的函數名稱
|
|
|
1999 |
$result["function"]=__FUNCTION__;
|
|
|
2000 |
|
|
|
2001 |
#如果 $conf 不為陣列
|
|
|
2002 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2003 |
|
| 3 |
liveuser |
2004 |
#設置執行失敗
|
|
|
2005 |
$result["status"]="false";
|
| 226 |
liveuser |
2006 |
|
| 3 |
liveuser |
2007 |
#設置執行錯誤訊息
|
|
|
2008 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2009 |
|
|
|
2010 |
#如果傳入的參數為 null
|
|
|
2011 |
if($conf==null){
|
| 226 |
liveuser |
2012 |
|
| 3 |
liveuser |
2013 |
#設置執行錯誤訊息
|
|
|
2014 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2015 |
|
| 3 |
liveuser |
2016 |
}#if end
|
|
|
2017 |
|
|
|
2018 |
#回傳結果
|
|
|
2019 |
return $result;
|
| 226 |
liveuser |
2020 |
|
| 3 |
liveuser |
2021 |
}#if end
|
|
|
2022 |
|
|
|
2023 |
#取得使用的參數
|
|
|
2024 |
$result["argu"]=$conf;
|
|
|
2025 |
|
|
|
2026 |
#檢查參數
|
|
|
2027 |
#函式說明:
|
|
|
2028 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2029 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2030 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2031 |
#$result["function"],當前執行的函式名稱.
|
|
|
2032 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2033 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2034 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2035 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2036 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2037 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2038 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2039 |
#必填寫的參數:
|
|
|
2040 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2041 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2042 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2043 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dirStr");
|
| 226 |
liveuser |
2044 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
2045 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
2046 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2047 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2048 |
#可以省略的參數:
|
|
|
2049 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2050 |
#$conf["canBeEmptyString"]="false";
|
|
|
2051 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2052 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wordsLong");
|
| 226 |
liveuser |
2053 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2054 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2055 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2056 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
2057 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2058 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2059 |
#參考資料來源:
|
|
|
2060 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2061 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2062 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2063 |
|
|
|
2064 |
#如果檢查有誤
|
|
|
2065 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2066 |
|
| 3 |
liveuser |
2067 |
#設置錯誤識別
|
|
|
2068 |
$result["status"]="false";
|
| 226 |
liveuser |
2069 |
|
| 3 |
liveuser |
2070 |
#設置錯誤訊息
|
|
|
2071 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2072 |
|
| 3 |
liveuser |
2073 |
#回傳結果
|
|
|
2074 |
return $result;
|
| 226 |
liveuser |
2075 |
|
| 3 |
liveuser |
2076 |
}#if end
|
| 226 |
liveuser |
2077 |
|
| 3 |
liveuser |
2078 |
#如果檢查不通過
|
|
|
2079 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2080 |
|
| 3 |
liveuser |
2081 |
#設置錯誤識別
|
|
|
2082 |
$result["status"]="false";
|
| 226 |
liveuser |
2083 |
|
| 3 |
liveuser |
2084 |
#設置錯誤訊息
|
|
|
2085 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2086 |
|
| 3 |
liveuser |
2087 |
#回傳結果
|
|
|
2088 |
return $result;
|
| 226 |
liveuser |
2089 |
|
| 3 |
liveuser |
2090 |
}#if end
|
| 226 |
liveuser |
2091 |
|
| 3 |
liveuser |
2092 |
#初始化儲存原始路徑字串
|
|
|
2093 |
$result["oriPath"]=$conf["dirStr"];
|
| 226 |
liveuser |
2094 |
|
| 3 |
liveuser |
2095 |
#初始化用來儲存輸出內容的元素.
|
|
|
2096 |
$result["changedPath"]="";
|
| 226 |
liveuser |
2097 |
|
| 3 |
liveuser |
2098 |
#初始化暫存的字串目錄
|
|
|
2099 |
$tempDirStrArray=array();
|
| 226 |
liveuser |
2100 |
|
| 3 |
liveuser |
2101 |
#用 / 進行分割
|
|
|
2102 |
#函式說明:
|
|
|
2103 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
2104 |
#回傳的參數:
|
|
|
2105 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2106 |
#$result["error"],錯誤訊息陣列
|
|
|
2107 |
#$result["function"],當前執行的函數名稱.
|
|
|
2108 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
2109 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
2110 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
2111 |
#必填參數:
|
|
|
2112 |
$conf["stringProcess::spiltString"]["stringIn"]=$conf["dirStr"];#要處理的字串。
|
|
|
2113 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
2114 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
2115 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
2116 |
|
| 3 |
liveuser |
2117 |
#如果分割失敗
|
|
|
2118 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
2119 |
|
| 3 |
liveuser |
2120 |
#設置錯誤識別
|
|
|
2121 |
$result["status"]="false";
|
| 226 |
liveuser |
2122 |
|
| 3 |
liveuser |
2123 |
#設置錯誤訊息
|
|
|
2124 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
2125 |
|
| 3 |
liveuser |
2126 |
#回傳結果
|
|
|
2127 |
return $result;
|
| 226 |
liveuser |
2128 |
|
| 3 |
liveuser |
2129 |
}#if end
|
| 226 |
liveuser |
2130 |
|
| 3 |
liveuser |
2131 |
#分成幾段就執行幾次
|
|
|
2132 |
for($i=0;$i<$spiltString["dataCounts"];$i++){
|
| 226 |
liveuser |
2133 |
|
| 3 |
liveuser |
2134 |
#如果是往上層目錄的「..」
|
|
|
2135 |
if($spiltString["dataArray"][$i]===".."){
|
| 226 |
liveuser |
2136 |
|
| 3 |
liveuser |
2137 |
#如果陣列不為空
|
|
|
2138 |
if($tempDirStrArray!==array()){
|
| 226 |
liveuser |
2139 |
|
| 3 |
liveuser |
2140 |
#如果前面有非 ".." 的目錄名稱
|
|
|
2141 |
if($tempDirStrArray[count($tempDirStrArray)-1]!==".."){
|
| 226 |
liveuser |
2142 |
|
| 3 |
liveuser |
2143 |
#函式說明:
|
|
|
2144 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
2145 |
#回傳結果:
|
|
|
2146 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2147 |
#$result["error"],錯誤訊息
|
|
|
2148 |
#$result["function"],當前執行的函數
|
|
|
2149 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
2150 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
2151 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
2152 |
#必填參數:
|
|
|
2153 |
$conf["arrays::eraseElement"]["rawInputArray"]=$tempDirStrArray;#要處理的原始數字陣列
|
| 226 |
liveuser |
2154 |
$conf["arrays::eraseElement"]["eraseElementKey"]="".(count($tempDirStrArray)-1)."";#要移除的元素key值
|
| 3 |
liveuser |
2155 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
2156 |
unset($conf["arrays::eraseElement"]);
|
| 226 |
liveuser |
2157 |
|
| 3 |
liveuser |
2158 |
#如果移除失敗
|
|
|
2159 |
if($eraseElement["status"]=="false"){
|
| 226 |
liveuser |
2160 |
|
| 3 |
liveuser |
2161 |
#設置錯誤識別
|
|
|
2162 |
$result["status"]="false";
|
| 226 |
liveuser |
2163 |
|
| 3 |
liveuser |
2164 |
#設置錯誤訊息
|
|
|
2165 |
$result["error"]=$eraseElement;
|
| 226 |
liveuser |
2166 |
|
| 3 |
liveuser |
2167 |
#回傳結果
|
|
|
2168 |
return $result;
|
| 226 |
liveuser |
2169 |
|
| 3 |
liveuser |
2170 |
}#if end
|
| 226 |
liveuser |
2171 |
|
| 3 |
liveuser |
2172 |
#取得新陣列
|
|
|
2173 |
$tempDirStrArray=$eraseElement["content"]["byNumber"];
|
| 226 |
liveuser |
2174 |
|
| 3 |
liveuser |
2175 |
}#if end
|
| 226 |
liveuser |
2176 |
|
|
|
2177 |
#反之
|
| 3 |
liveuser |
2178 |
else{
|
| 226 |
liveuser |
2179 |
|
| 3 |
liveuser |
2180 |
#儲存 ".."
|
|
|
2181 |
$tempDirStrArray[]=$spiltString["dataArray"][$i];
|
| 226 |
liveuser |
2182 |
|
| 3 |
liveuser |
2183 |
}
|
| 226 |
liveuser |
2184 |
|
|
|
2185 |
}#if end
|
|
|
2186 |
|
| 3 |
liveuser |
2187 |
#反之
|
|
|
2188 |
else{
|
| 226 |
liveuser |
2189 |
|
| 3 |
liveuser |
2190 |
#儲存 ".."
|
|
|
2191 |
$tempDirStrArray[]=$spiltString["dataArray"][$i];
|
| 226 |
liveuser |
2192 |
|
| 3 |
liveuser |
2193 |
}#else end
|
| 226 |
liveuser |
2194 |
|
| 3 |
liveuser |
2195 |
}#if end
|
| 226 |
liveuser |
2196 |
|
| 3 |
liveuser |
2197 |
#反之
|
|
|
2198 |
else{
|
| 226 |
liveuser |
2199 |
|
| 3 |
liveuser |
2200 |
#儲存路徑片段
|
|
|
2201 |
$tempDirStrArray[]=$spiltString["dataArray"][$i];
|
| 226 |
liveuser |
2202 |
|
| 3 |
liveuser |
2203 |
}#else end
|
| 226 |
liveuser |
2204 |
|
| 3 |
liveuser |
2205 |
}#for end
|
| 226 |
liveuser |
2206 |
|
| 3 |
liveuser |
2207 |
#debug
|
|
|
2208 |
#var_dump($tempDirStrArray);exit;
|
| 226 |
liveuser |
2209 |
|
| 3 |
liveuser |
2210 |
#檢查 $conf["dirStr"] 是否為 「/」 開頭
|
|
|
2211 |
#函式說明:
|
|
|
2212 |
#取得符合特定字首與字尾的字串
|
|
|
2213 |
#回傳結果:
|
|
|
2214 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
2215 |
#$result["function"],當前執行的函數名稱.
|
|
|
2216 |
#$result["error"],錯誤訊息陣列.
|
|
|
2217 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
2218 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
2219 |
#必填參數:
|
|
|
2220 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
2221 |
$conf["search::getMeetConditionsString"]["checkString"]=$conf["dirStr"];
|
|
|
2222 |
#可省略參數:
|
|
|
2223 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
2224 |
$conf["search::getMeetConditionsString"]["frontWord"]="/";
|
|
|
2225 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
2226 |
#$conf["tailWord"]="";
|
|
|
2227 |
#參考資料:
|
|
|
2228 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
2229 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
2230 |
unset($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
2231 |
|
| 3 |
liveuser |
2232 |
#如果尋找關鍵字失敗
|
|
|
2233 |
if($getMeetConditionsString["status"]=="false"){
|
| 226 |
liveuser |
2234 |
|
| 3 |
liveuser |
2235 |
#設置錯誤識別
|
|
|
2236 |
$result["status"]="false";
|
| 226 |
liveuser |
2237 |
|
| 3 |
liveuser |
2238 |
#設置錯誤訊息
|
|
|
2239 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
2240 |
|
| 3 |
liveuser |
2241 |
#回傳結果
|
|
|
2242 |
return $result;
|
| 226 |
liveuser |
2243 |
|
| 3 |
liveuser |
2244 |
}#if end
|
| 226 |
liveuser |
2245 |
|
| 3 |
liveuser |
2246 |
#如果有關鍵字「/」在開頭
|
|
|
2247 |
if($getMeetConditionsString["founded"]=="true"){
|
| 226 |
liveuser |
2248 |
|
| 3 |
liveuser |
2249 |
#初始化改變好的路徑為「/」開頭
|
|
|
2250 |
$result["changedPath"]="/";
|
| 226 |
liveuser |
2251 |
|
| 3 |
liveuser |
2252 |
}#if end
|
| 226 |
liveuser |
2253 |
|
| 3 |
liveuser |
2254 |
#$tempDirStrArray有幾個元素就執行幾次
|
|
|
2255 |
for($i=0;$i<count($tempDirStrArray);$i++){
|
| 226 |
liveuser |
2256 |
|
| 3 |
liveuser |
2257 |
#如果是最後一個元素
|
|
|
2258 |
if($i==(count($tempDirStrArray)-1)){
|
| 226 |
liveuser |
2259 |
|
| 3 |
liveuser |
2260 |
#檢查 $conf["dirStr"] 是否有 「/」 結尾
|
|
|
2261 |
#函式說明:
|
|
|
2262 |
#取得符合特定字首與字尾的字串
|
|
|
2263 |
#回傳結果:
|
|
|
2264 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
2265 |
#$result["function"],當前執行的函數名稱.
|
|
|
2266 |
#$result["error"],錯誤訊息陣列.
|
|
|
2267 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
2268 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
2269 |
#必填參數:
|
|
|
2270 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
2271 |
$conf["search::getMeetConditionsString"]["checkString"]=$conf["dirStr"];
|
|
|
2272 |
#可省略參數:
|
|
|
2273 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
2274 |
#$conf["search::getMeetConditionsString"]["frontWord"]=".";
|
|
|
2275 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
2276 |
$conf["search::getMeetConditionsString"]["tailWord"]="/";
|
|
|
2277 |
#參考資料:
|
|
|
2278 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
2279 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
2280 |
unset($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
2281 |
|
| 3 |
liveuser |
2282 |
#如果尋找關鍵字失敗
|
|
|
2283 |
if($getMeetConditionsString["status"]=="false"){
|
| 226 |
liveuser |
2284 |
|
| 3 |
liveuser |
2285 |
#設置錯誤識別
|
|
|
2286 |
$result["status"]="false";
|
| 226 |
liveuser |
2287 |
|
| 3 |
liveuser |
2288 |
#設置錯誤訊息
|
|
|
2289 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
2290 |
|
| 3 |
liveuser |
2291 |
#回傳結果
|
|
|
2292 |
return $result;
|
| 226 |
liveuser |
2293 |
|
| 3 |
liveuser |
2294 |
}#if end
|
| 226 |
liveuser |
2295 |
|
| 3 |
liveuser |
2296 |
#如果有關鍵字「/」在結尾
|
|
|
2297 |
if($getMeetConditionsString["founded"]=="true"){
|
| 226 |
liveuser |
2298 |
|
| 3 |
liveuser |
2299 |
#串接直觀的路徑與結尾加上「/」
|
|
|
2300 |
$result["changedPath"]=$result["changedPath"].$tempDirStrArray[$i]."/";
|
| 226 |
liveuser |
2301 |
|
| 3 |
liveuser |
2302 |
}#if end
|
| 226 |
liveuser |
2303 |
|
| 3 |
liveuser |
2304 |
#反之
|
|
|
2305 |
else{
|
| 226 |
liveuser |
2306 |
|
| 3 |
liveuser |
2307 |
#串接直觀的路徑與結尾加上「/」
|
|
|
2308 |
$result["changedPath"]=$result["changedPath"].$tempDirStrArray[$i];
|
| 226 |
liveuser |
2309 |
|
| 3 |
liveuser |
2310 |
}#else end
|
| 226 |
liveuser |
2311 |
|
| 3 |
liveuser |
2312 |
}#if end
|
| 226 |
liveuser |
2313 |
|
|
|
2314 |
#反之
|
| 3 |
liveuser |
2315 |
else{
|
| 226 |
liveuser |
2316 |
|
| 3 |
liveuser |
2317 |
#串接直觀的路徑與結尾加上「/」
|
|
|
2318 |
$result["changedPath"]=$result["changedPath"].$tempDirStrArray[$i]."/";
|
| 226 |
liveuser |
2319 |
|
| 3 |
liveuser |
2320 |
}#else end
|
| 226 |
liveuser |
2321 |
|
| 3 |
liveuser |
2322 |
}#for end
|
| 226 |
liveuser |
2323 |
|
| 3 |
liveuser |
2324 |
#設置執行成功的識別
|
|
|
2325 |
$result["status"]="true";
|
| 226 |
liveuser |
2326 |
|
| 3 |
liveuser |
2327 |
#回傳結果
|
|
|
2328 |
return $result;
|
| 226 |
liveuser |
2329 |
|
| 3 |
liveuser |
2330 |
}#function changeDirByDotDotSolidus end
|
|
|
2331 |
|
|
|
2332 |
/*
|
|
|
2333 |
#函式說明:
|
| 226 |
liveuser |
2334 |
#將陣列裡的元素內容用特定符號連接在一起變成字串.
|
| 3 |
liveuser |
2335 |
#回傳結果:
|
|
|
2336 |
#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
|
|
|
2337 |
#$result["function"],當前執行的函數.
|
|
|
2338 |
#$result["error"],錯誤訊息陣列.
|
|
|
2339 |
#$result["content"],處理過後的字串.
|
|
|
2340 |
#必填參數:
|
|
|
2341 |
#$conf["inputArray"],字串陣列,要處理的陣列.
|
|
|
2342 |
$conf["inputArray"]=array();
|
|
|
2343 |
#$conf["combineSymbol"],字串,用來連結各元素的符號.
|
|
|
2344 |
$conf["combineSymbol"]=",";
|
|
|
2345 |
#可省略參數:
|
|
|
2346 |
#無.
|
|
|
2347 |
#參考資料:
|
|
|
2348 |
#無.
|
|
|
2349 |
#備註:
|
|
|
2350 |
#無.
|
|
|
2351 |
*/
|
|
|
2352 |
public static function combineElementWithSymbol(&$conf){
|
| 226 |
liveuser |
2353 |
|
| 3 |
liveuser |
2354 |
#初始化要回傳的內容
|
|
|
2355 |
$result=array();
|
|
|
2356 |
|
|
|
2357 |
#取得當前執行的函數名稱
|
|
|
2358 |
$result["function"]=__FUNCTION__;
|
|
|
2359 |
|
|
|
2360 |
#如果 $conf 不為陣列
|
|
|
2361 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2362 |
|
| 3 |
liveuser |
2363 |
#設置執行失敗
|
|
|
2364 |
$result["status"]="false";
|
| 226 |
liveuser |
2365 |
|
| 3 |
liveuser |
2366 |
#設置執行錯誤訊息
|
|
|
2367 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2368 |
|
|
|
2369 |
#如果傳入的參數為 null
|
|
|
2370 |
if($conf==null){
|
| 226 |
liveuser |
2371 |
|
| 3 |
liveuser |
2372 |
#設置執行錯誤訊息
|
|
|
2373 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2374 |
|
| 3 |
liveuser |
2375 |
}#if end
|
|
|
2376 |
|
|
|
2377 |
#回傳結果
|
|
|
2378 |
return $result;
|
| 226 |
liveuser |
2379 |
|
| 3 |
liveuser |
2380 |
}#if end
|
|
|
2381 |
|
|
|
2382 |
#檢查參數
|
|
|
2383 |
#函式說明:
|
|
|
2384 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2385 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2386 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2387 |
#$result["function"],當前執行的函式名稱.
|
|
|
2388 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2389 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2390 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2391 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2392 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2393 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2394 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2395 |
#必填寫的參數:
|
|
|
2396 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2397 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2398 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2399 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("inputArray","combineSymbol");
|
| 226 |
liveuser |
2400 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
2401 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
2402 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2403 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2404 |
#可以省略的參數:
|
|
|
2405 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2406 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2407 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2408 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wordsLong");
|
| 226 |
liveuser |
2409 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2410 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2411 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2412 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
2413 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2414 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2415 |
#參考資料來源:
|
|
|
2416 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2417 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2418 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2419 |
|
|
|
2420 |
#如果檢查有誤
|
|
|
2421 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2422 |
|
| 3 |
liveuser |
2423 |
#設置錯誤識別
|
|
|
2424 |
$result["status"]="false";
|
| 226 |
liveuser |
2425 |
|
| 3 |
liveuser |
2426 |
#設置錯誤訊息
|
|
|
2427 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2428 |
|
| 3 |
liveuser |
2429 |
#回傳結果
|
|
|
2430 |
return $result;
|
| 226 |
liveuser |
2431 |
|
| 3 |
liveuser |
2432 |
}#if end
|
| 226 |
liveuser |
2433 |
|
| 3 |
liveuser |
2434 |
#如果檢查不通過
|
|
|
2435 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2436 |
|
| 3 |
liveuser |
2437 |
#設置錯誤識別
|
|
|
2438 |
$result["status"]="false";
|
| 226 |
liveuser |
2439 |
|
| 3 |
liveuser |
2440 |
#設置錯誤訊息
|
|
|
2441 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2442 |
|
| 3 |
liveuser |
2443 |
#回傳結果
|
|
|
2444 |
return $result;
|
| 226 |
liveuser |
2445 |
|
| 3 |
liveuser |
2446 |
}#if end
|
| 226 |
liveuser |
2447 |
|
| 3 |
liveuser |
2448 |
#初始化要回傳的字串
|
|
|
2449 |
$result["content"]="";
|
| 226 |
liveuser |
2450 |
|
| 3 |
liveuser |
2451 |
#針對 $conf["inputArray"] 的每個元素
|
|
|
2452 |
for($i=0;$i<count($conf["inputArray"]);$i++){
|
| 226 |
liveuser |
2453 |
|
| 3 |
liveuser |
2454 |
#如果是第一筆
|
|
|
2455 |
if($i==0){
|
| 226 |
liveuser |
2456 |
|
| 3 |
liveuser |
2457 |
#將字串連接在一塊
|
|
|
2458 |
$result["content"]=$result["content"].$conf["inputArray"][$i];
|
| 226 |
liveuser |
2459 |
|
| 3 |
liveuser |
2460 |
}#if end
|
| 226 |
liveuser |
2461 |
|
| 3 |
liveuser |
2462 |
#反之是最後一筆
|
|
|
2463 |
else{
|
| 226 |
liveuser |
2464 |
|
| 3 |
liveuser |
2465 |
#將字串連接在一塊
|
|
|
2466 |
$result["content"]=$result["content"].$conf["combineSymbol"].$conf["inputArray"][$i];
|
| 226 |
liveuser |
2467 |
|
| 3 |
liveuser |
2468 |
}#else end
|
| 226 |
liveuser |
2469 |
|
| 3 |
liveuser |
2470 |
}#foreach end
|
| 226 |
liveuser |
2471 |
|
| 3 |
liveuser |
2472 |
#執行到這邊代表執行正常
|
|
|
2473 |
$result["status"]="true";
|
| 226 |
liveuser |
2474 |
|
| 3 |
liveuser |
2475 |
#回傳結果
|
|
|
2476 |
return $result;
|
| 226 |
liveuser |
2477 |
|
| 3 |
liveuser |
2478 |
}#function combineElementWithSymbol end
|
|
|
2479 |
|
|
|
2480 |
/*
|
|
|
2481 |
#函式說明:
|
|
|
2482 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
2483 |
#回傳結果:
|
|
|
2484 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 226 |
liveuser |
2485 |
#$result["error"],錯誤訊息陣列.
|
| 3 |
liveuser |
2486 |
#$result["function"],當前執行的函數名稱.
|
|
|
2487 |
#$result["content"],分割好的內容陣列.
|
|
|
2488 |
#$result["length"],unicode字串的長度.
|
|
|
2489 |
#必填參數:
|
|
|
2490 |
#$conf["str"],字串",要分割的字串.
|
|
|
2491 |
$conf["str"]="";
|
|
|
2492 |
#可省略參數:
|
|
|
2493 |
#$conf["length"],整數,分割的長度.
|
|
|
2494 |
#$conf["length"]=1;
|
|
|
2495 |
#參考資料:
|
|
|
2496 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2497 |
#備註:
|
|
|
2498 |
#無.
|
|
|
2499 |
*/
|
|
|
2500 |
public static function str_split_unicode(&$conf){
|
| 226 |
liveuser |
2501 |
|
| 3 |
liveuser |
2502 |
#檢查參數
|
|
|
2503 |
#函式說明:
|
|
|
2504 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2505 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2506 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2507 |
#$result["function"],當前執行的函式名稱.
|
|
|
2508 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2509 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2510 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2511 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2512 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2513 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2514 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2515 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2516 |
#必填寫的參數:
|
|
|
2517 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2518 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2519 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2520 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("str");
|
|
|
2521 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2522 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
2523 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2524 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2525 |
#可以省略的參數:
|
|
|
2526 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2527 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2528 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2529 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2530 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2531 |
#$conf["canBeEmpty"]=array();
|
|
|
2532 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2533 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2534 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2535 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
|
| 226 |
liveuser |
2536 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2537 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
|
|
|
2538 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2539 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(1);
|
|
|
2540 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2541 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2542 |
#參考資料來源:
|
|
|
2543 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2544 |
#建議:
|
|
|
2545 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
2546 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2547 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
2548 |
|
| 3 |
liveuser |
2549 |
#如果檢查參數失敗
|
|
|
2550 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
2551 |
|
| 3 |
liveuser |
2552 |
#設置執行失敗
|
|
|
2553 |
$result["status"]="false";
|
| 226 |
liveuser |
2554 |
|
| 3 |
liveuser |
2555 |
#設置執行錯誤訊息
|
|
|
2556 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2557 |
|
| 3 |
liveuser |
2558 |
#回傳結果
|
|
|
2559 |
return $result;
|
| 226 |
liveuser |
2560 |
|
|
|
2561 |
}#if end
|
|
|
2562 |
|
| 3 |
liveuser |
2563 |
#如果檢查參數不通過
|
|
|
2564 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
2565 |
|
| 3 |
liveuser |
2566 |
#設置執行失敗
|
|
|
2567 |
$result["status"]="false";
|
| 226 |
liveuser |
2568 |
|
| 3 |
liveuser |
2569 |
#設置執行錯誤訊息
|
|
|
2570 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2571 |
|
| 3 |
liveuser |
2572 |
#回傳結果
|
|
|
2573 |
return $result;
|
| 226 |
liveuser |
2574 |
|
| 3 |
liveuser |
2575 |
}#if end
|
| 226 |
liveuser |
2576 |
|
| 3 |
liveuser |
2577 |
#要分割的長度若小於1
|
|
|
2578 |
if($conf["length"]<1){
|
| 226 |
liveuser |
2579 |
|
| 3 |
liveuser |
2580 |
#設置執行失敗
|
|
|
2581 |
$result["status"]="false";
|
| 226 |
liveuser |
2582 |
|
| 3 |
liveuser |
2583 |
#設置執行錯誤訊息
|
|
|
2584 |
$result["error"][]="參數 \$conf[\"length\"] 不得小於 1";
|
| 226 |
liveuser |
2585 |
|
| 3 |
liveuser |
2586 |
#回傳結果
|
|
|
2587 |
return $result;
|
| 226 |
liveuser |
2588 |
|
| 3 |
liveuser |
2589 |
}#if end
|
| 226 |
liveuser |
2590 |
|
| 3 |
liveuser |
2591 |
#初始化要回傳的字串陣列
|
|
|
2592 |
$result["content"]=array();
|
| 226 |
liveuser |
2593 |
|
| 3 |
liveuser |
2594 |
#取得 $conf["str"] 的長度
|
|
|
2595 |
$result["length"]=mb_strlen($conf["str"],"UTF-8");
|
| 226 |
liveuser |
2596 |
|
| 3 |
liveuser |
2597 |
#依據 $conf["str"] 與 $conf["length"]
|
|
|
2598 |
for($i=0;$i<$result["length"];$i=$i+$conf["length"]){
|
| 226 |
liveuser |
2599 |
|
| 3 |
liveuser |
2600 |
#從位置 $i 往後讀 $conf["length"] 個字,編碼為"UTF-8"
|
|
|
2601 |
$result["content"][]=mb_substr($conf["str"], $i, $conf["length"],"UTF-8");
|
| 226 |
liveuser |
2602 |
|
| 3 |
liveuser |
2603 |
}#for end
|
| 226 |
liveuser |
2604 |
|
| 3 |
liveuser |
2605 |
#設置執行正常
|
| 226 |
liveuser |
2606 |
$result["status"]="true";
|
|
|
2607 |
|
|
|
2608 |
#回傳結果
|
| 3 |
liveuser |
2609 |
return $result;
|
| 226 |
liveuser |
2610 |
|
| 3 |
liveuser |
2611 |
}#function str_split_unicode end
|
|
|
2612 |
|
|
|
2613 |
/*
|
|
|
2614 |
#函式說明:
|
|
|
2615 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
2616 |
#回傳結果:
|
|
|
2617 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2618 |
#$result["error"],錯誤訊息陣列.
|
|
|
2619 |
#$result["warning"],警告訊息鎮列.
|
|
|
2620 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
2621 |
#$result["function"],當前執行的函數名稱.
|
|
|
2622 |
#$result["argu"],使用的參數.
|
|
|
2623 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
2624 |
#$result["content"],處理好的的字串內容.
|
|
|
2625 |
#$result["deleted"],被移除的內容.
|
|
|
2626 |
#必填參數:
|
|
|
2627 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2628 |
$conf["stringIn"]="";
|
|
|
2629 |
#$conf["keyWord"],字串,特定字串.
|
|
|
2630 |
$conf["keyWord"]="";
|
|
|
2631 |
#可省略參數:
|
|
|
2632 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
2633 |
#$conf["recursive"]="true";
|
|
|
2634 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
2635 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
2636 |
#參考資料:
|
|
|
2637 |
#無.
|
|
|
2638 |
#備註:
|
|
|
2639 |
#無.
|
|
|
2640 |
*/
|
|
|
2641 |
public static function delStrBeforeKeyWord(&$conf){
|
| 226 |
liveuser |
2642 |
|
| 3 |
liveuser |
2643 |
#初始化要回傳的內容
|
|
|
2644 |
$result=array();
|
|
|
2645 |
|
|
|
2646 |
#取得當前執行的函數名稱
|
|
|
2647 |
$result["function"]=__FUNCTION__;
|
|
|
2648 |
|
|
|
2649 |
#如果 $conf 不為陣列
|
|
|
2650 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2651 |
|
| 3 |
liveuser |
2652 |
#設置執行失敗
|
|
|
2653 |
$result["status"]="false";
|
| 226 |
liveuser |
2654 |
|
| 3 |
liveuser |
2655 |
#設置執行錯誤訊息
|
|
|
2656 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2657 |
|
|
|
2658 |
#如果傳入的參數為 null
|
|
|
2659 |
if($conf==null){
|
| 226 |
liveuser |
2660 |
|
| 3 |
liveuser |
2661 |
#設置執行錯誤訊息
|
|
|
2662 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2663 |
|
| 3 |
liveuser |
2664 |
}#if end
|
|
|
2665 |
|
|
|
2666 |
#回傳結果
|
|
|
2667 |
return $result;
|
| 226 |
liveuser |
2668 |
|
| 3 |
liveuser |
2669 |
}#if end
|
|
|
2670 |
|
|
|
2671 |
#取得參數
|
|
|
2672 |
$result["argu"]=$conf;
|
|
|
2673 |
|
|
|
2674 |
#檢查參數
|
|
|
2675 |
#函式說明:
|
|
|
2676 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2677 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2678 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2679 |
#$result["function"],當前執行的函式名稱.
|
|
|
2680 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2681 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2682 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2683 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2684 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2685 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2686 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2687 |
#必填寫的參數:
|
|
|
2688 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2689 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2690 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2691 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","keyWord");
|
| 226 |
liveuser |
2692 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
2693 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
2694 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2695 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2696 |
#可以省略的參數:
|
| 218 |
liveuser |
2697 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2698 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
| 3 |
liveuser |
2699 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2700 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","lastResult");
|
| 226 |
liveuser |
2701 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2702 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array");
|
|
|
2703 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2704 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null);
|
|
|
2705 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2706 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2707 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2708 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
2709 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2710 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("stringIn");
|
|
|
2711 |
#參考資料來源:
|
|
|
2712 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2713 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2714 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2715 |
|
|
|
2716 |
#如果檢查有誤
|
| 218 |
liveuser |
2717 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
2718 |
|
| 3 |
liveuser |
2719 |
#設置錯誤識別
|
|
|
2720 |
$result["status"]="false";
|
| 226 |
liveuser |
2721 |
|
| 3 |
liveuser |
2722 |
#設置錯誤訊息
|
|
|
2723 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2724 |
|
| 3 |
liveuser |
2725 |
#回傳結果
|
|
|
2726 |
return $result;
|
| 226 |
liveuser |
2727 |
|
| 3 |
liveuser |
2728 |
}#if end
|
| 226 |
liveuser |
2729 |
|
| 3 |
liveuser |
2730 |
#如果檢查不通過
|
| 218 |
liveuser |
2731 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
2732 |
|
| 3 |
liveuser |
2733 |
#設置錯誤識別
|
|
|
2734 |
$result["status"]="false";
|
| 226 |
liveuser |
2735 |
|
| 3 |
liveuser |
2736 |
#設置錯誤訊息
|
|
|
2737 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2738 |
|
| 3 |
liveuser |
2739 |
#回傳結果
|
|
|
2740 |
return $result;
|
| 226 |
liveuser |
2741 |
|
| 3 |
liveuser |
2742 |
}#if end
|
| 226 |
liveuser |
2743 |
|
| 3 |
liveuser |
2744 |
#如果要處理的字串已經為空了
|
|
|
2745 |
if($conf["stringIn"]===""){
|
| 226 |
liveuser |
2746 |
|
| 3 |
liveuser |
2747 |
#擁有上次執行的結果.
|
|
|
2748 |
if(isset($conf["lastResult"])){
|
| 226 |
liveuser |
2749 |
|
| 3 |
liveuser |
2750 |
#回傳上次結果
|
|
|
2751 |
return $conf["lastResult"];
|
| 226 |
liveuser |
2752 |
|
| 3 |
liveuser |
2753 |
}#if end
|
| 226 |
liveuser |
2754 |
|
| 218 |
liveuser |
2755 |
#如果關鍵字也是空字串
|
|
|
2756 |
if($conf["keyWord"]===""){
|
| 226 |
liveuser |
2757 |
|
| 218 |
liveuser |
2758 |
#設置有找到關鍵字
|
|
|
2759 |
$result["founded"]="true";
|
| 226 |
liveuser |
2760 |
|
| 218 |
liveuser |
2761 |
#初始化儲存原始的字串
|
|
|
2762 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2763 |
|
| 218 |
liveuser |
2764 |
#結果跟原始字串一樣
|
|
|
2765 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
2766 |
|
| 218 |
liveuser |
2767 |
#設置執行正常識別
|
|
|
2768 |
$result["status"]="true";
|
| 226 |
liveuser |
2769 |
|
| 218 |
liveuser |
2770 |
#回傳結果
|
|
|
2771 |
return $result;
|
| 226 |
liveuser |
2772 |
|
| 218 |
liveuser |
2773 |
}#if end
|
| 226 |
liveuser |
2774 |
|
| 218 |
liveuser |
2775 |
#設置執行正常識別
|
| 3 |
liveuser |
2776 |
$result["status"]="true";
|
| 226 |
liveuser |
2777 |
|
| 3 |
liveuser |
2778 |
#設置警告訊息
|
|
|
2779 |
$result["warning"][]="要處理的參數 stringIn 為空,且沒有參數 lastResult 存在";
|
| 226 |
liveuser |
2780 |
|
| 3 |
liveuser |
2781 |
#初始化儲存原始的字串
|
|
|
2782 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2783 |
|
| 3 |
liveuser |
2784 |
#結果跟原始字串一樣
|
|
|
2785 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
2786 |
|
| 3 |
liveuser |
2787 |
#設置沒有找到關鍵字
|
|
|
2788 |
$result["founded"]="false";
|
| 226 |
liveuser |
2789 |
|
| 3 |
liveuser |
2790 |
#回傳結果
|
|
|
2791 |
return $result;
|
| 226 |
liveuser |
2792 |
|
| 3 |
liveuser |
2793 |
}#if end
|
| 226 |
liveuser |
2794 |
|
| 218 |
liveuser |
2795 |
#如果要判斷的輸入為空字串
|
|
|
2796 |
if($conf["stringIn"]===""){
|
| 226 |
liveuser |
2797 |
|
| 218 |
liveuser |
2798 |
#初始化分割好內容
|
|
|
2799 |
$spiltedStringIn=array();
|
| 226 |
liveuser |
2800 |
|
| 218 |
liveuser |
2801 |
}#if end
|
| 226 |
liveuser |
2802 |
|
| 218 |
liveuser |
2803 |
#反之
|
|
|
2804 |
else{
|
| 226 |
liveuser |
2805 |
|
| 218 |
liveuser |
2806 |
#將要處理的字串用unicode編碼來一個個字分割.
|
|
|
2807 |
#函式說明:
|
|
|
2808 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
2809 |
#回傳結果:
|
|
|
2810 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 226 |
liveuser |
2811 |
#$result["error"],錯誤訊息陣列.
|
| 218 |
liveuser |
2812 |
#$result["function"],當前執行的函數名稱.
|
|
|
2813 |
#$result["content"],分割好的內容.
|
|
|
2814 |
#$result["length"],unicode字串的長度.
|
|
|
2815 |
#必填參數:
|
|
|
2816 |
#$conf["str"],字串",要分割的字串.
|
|
|
2817 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["stringIn"];
|
|
|
2818 |
#可省略參數:
|
|
|
2819 |
#$conf["length"],整數,分割的長度.
|
|
|
2820 |
#$conf["length"]=1;
|
|
|
2821 |
#參考資料:
|
|
|
2822 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2823 |
$str_split_unicode=self::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
2824 |
unset($conf["stringProcess::str_split_unicode"]);
|
| 226 |
liveuser |
2825 |
|
| 218 |
liveuser |
2826 |
#如果分割字串失敗
|
|
|
2827 |
if($str_split_unicode["status"]==="false"){
|
| 226 |
liveuser |
2828 |
|
| 218 |
liveuser |
2829 |
#設置錯誤識別
|
|
|
2830 |
$result["status"]="false";
|
| 226 |
liveuser |
2831 |
|
| 218 |
liveuser |
2832 |
#設置錯誤訊息
|
|
|
2833 |
$result["error"]=$str_split_unicode;
|
| 226 |
liveuser |
2834 |
|
| 218 |
liveuser |
2835 |
#回傳結果
|
|
|
2836 |
return $result;
|
| 226 |
liveuser |
2837 |
|
| 218 |
liveuser |
2838 |
}#if end
|
| 226 |
liveuser |
2839 |
|
| 218 |
liveuser |
2840 |
#取得分割好的字串
|
|
|
2841 |
$spiltedStringIn=$str_split_unicode["content"];
|
| 226 |
liveuser |
2842 |
|
|
|
2843 |
}#else
|
|
|
2844 |
|
| 218 |
liveuser |
2845 |
#如果關鍵字為空字串
|
|
|
2846 |
if($conf["keyWord"]===""){
|
| 226 |
liveuser |
2847 |
|
| 218 |
liveuser |
2848 |
#初始化分割好內容
|
|
|
2849 |
$spiltedKeyWord=array();
|
| 226 |
liveuser |
2850 |
|
| 3 |
liveuser |
2851 |
}#if end
|
| 226 |
liveuser |
2852 |
|
| 218 |
liveuser |
2853 |
#反之
|
|
|
2854 |
else{
|
| 226 |
liveuser |
2855 |
|
| 218 |
liveuser |
2856 |
#將要處理的關鍵字用unicode編碼來一個個字分割.
|
|
|
2857 |
#函式說明:
|
|
|
2858 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
2859 |
#回傳結果:
|
|
|
2860 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 226 |
liveuser |
2861 |
#$result["error"],錯誤訊息陣列.
|
| 218 |
liveuser |
2862 |
#$result["function"],當前執行的函數名稱.
|
|
|
2863 |
#$result["content"],分割好的內容.
|
|
|
2864 |
#$result["length"],unicode字串的長度.
|
|
|
2865 |
#必填參數:
|
|
|
2866 |
#$conf["str"],字串",要分割的字串.
|
|
|
2867 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["keyWord"];
|
|
|
2868 |
#可省略參數:
|
|
|
2869 |
#$conf["length"],整數,分割的長度.
|
|
|
2870 |
#$conf["length"]=1;
|
|
|
2871 |
#參考資料:
|
|
|
2872 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2873 |
$str_split_unicode=self::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
2874 |
unset($conf["stringProcess::str_split_unicode"]);
|
| 226 |
liveuser |
2875 |
|
| 218 |
liveuser |
2876 |
#如果分割字串失敗
|
|
|
2877 |
if($str_split_unicode["status"]==="false"){
|
| 226 |
liveuser |
2878 |
|
| 218 |
liveuser |
2879 |
#設置錯誤識別
|
|
|
2880 |
$result["status"]="false";
|
| 226 |
liveuser |
2881 |
|
| 218 |
liveuser |
2882 |
#設置錯誤訊息
|
|
|
2883 |
$result["error"]=$str_split_unicode;
|
| 226 |
liveuser |
2884 |
|
| 218 |
liveuser |
2885 |
#回傳結果
|
|
|
2886 |
return $result;
|
| 226 |
liveuser |
2887 |
|
| 218 |
liveuser |
2888 |
}#if end
|
| 226 |
liveuser |
2889 |
|
| 218 |
liveuser |
2890 |
#取得分割好的字串
|
|
|
2891 |
$spiltedKeyWord=$str_split_unicode["content"];
|
| 226 |
liveuser |
2892 |
|
| 218 |
liveuser |
2893 |
}#else end
|
| 226 |
liveuser |
2894 |
|
| 3 |
liveuser |
2895 |
#如果關鍵字比要處理的字串長
|
|
|
2896 |
if(count($spiltedKeyWord)>count($spiltedStringIn)){
|
| 226 |
liveuser |
2897 |
|
| 3 |
liveuser |
2898 |
#如果有前次的結果
|
|
|
2899 |
if(isset($conf["lastResult"])){
|
| 226 |
liveuser |
2900 |
|
| 3 |
liveuser |
2901 |
#回傳之
|
|
|
2902 |
return $conf["lastResult"];
|
| 226 |
liveuser |
2903 |
|
| 3 |
liveuser |
2904 |
}#if end
|
| 226 |
liveuser |
2905 |
|
| 3 |
liveuser |
2906 |
#設置錯誤識別
|
|
|
2907 |
$result["status"]="true";
|
| 226 |
liveuser |
2908 |
|
| 3 |
liveuser |
2909 |
#設置錯誤訊息
|
|
|
2910 |
$result["warning"][]="變數 keyWord 不應該比變數 stringIn 長";
|
| 226 |
liveuser |
2911 |
|
| 3 |
liveuser |
2912 |
#初始化儲存原始的字串
|
|
|
2913 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2914 |
|
| 3 |
liveuser |
2915 |
#結果跟原始字串一樣
|
|
|
2916 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
2917 |
|
| 3 |
liveuser |
2918 |
#設置沒有找到關鍵字
|
|
|
2919 |
$result["founded"]="false";
|
| 226 |
liveuser |
2920 |
|
| 3 |
liveuser |
2921 |
#回傳結果
|
|
|
2922 |
return $result;
|
| 226 |
liveuser |
2923 |
|
| 3 |
liveuser |
2924 |
}#if end
|
| 226 |
liveuser |
2925 |
|
| 3 |
liveuser |
2926 |
#初始化儲存要移除第幾個字之前的內容(索引從0開始)
|
|
|
2927 |
$delCount=-1;
|
| 226 |
liveuser |
2928 |
|
| 3 |
liveuser |
2929 |
#初始化暫存關鍵字的第幾個字
|
| 218 |
liveuser |
2930 |
$wordCount=0;
|
| 226 |
liveuser |
2931 |
|
| 3 |
liveuser |
2932 |
#無窮迴圈
|
|
|
2933 |
for($i=0;$i<count($spiltedStringIn);$i++){
|
| 226 |
liveuser |
2934 |
|
| 218 |
liveuser |
2935 |
#如果關鍵字不存在
|
|
|
2936 |
if(!isset($spiltedKeyWord[$wordCount])){
|
| 226 |
liveuser |
2937 |
|
| 218 |
liveuser |
2938 |
#debug
|
|
|
2939 |
#var_dump(__LINE__,$spiltedStringIn,$spiltedStringIn[$i]);
|
| 226 |
liveuser |
2940 |
|
| 218 |
liveuser |
2941 |
#跳過
|
|
|
2942 |
continue;
|
| 226 |
liveuser |
2943 |
|
| 218 |
liveuser |
2944 |
}#if end
|
| 226 |
liveuser |
2945 |
|
| 3 |
liveuser |
2946 |
#如果有遇到相符合的字元
|
|
|
2947 |
if($spiltedStringIn[$i]===$spiltedKeyWord[$wordCount]){
|
| 226 |
liveuser |
2948 |
|
| 3 |
liveuser |
2949 |
#換尋找下個字元有無符合
|
|
|
2950 |
$wordCount++;
|
| 226 |
liveuser |
2951 |
|
| 3 |
liveuser |
2952 |
#如果下一個關鍵字字元不存在
|
|
|
2953 |
if(!isset($spiltedKeyWord[$wordCount])){
|
| 226 |
liveuser |
2954 |
|
| 3 |
liveuser |
2955 |
#代表有找到符合條件的關鍵字了
|
|
|
2956 |
$delCount=$i;
|
| 226 |
liveuser |
2957 |
|
| 3 |
liveuser |
2958 |
#跳出迴圈
|
|
|
2959 |
break;
|
| 226 |
liveuser |
2960 |
|
| 3 |
liveuser |
2961 |
}#if end
|
| 226 |
liveuser |
2962 |
|
| 3 |
liveuser |
2963 |
}#if end
|
| 226 |
liveuser |
2964 |
|
| 3 |
liveuser |
2965 |
#反之沒有遇到相符合的字元
|
|
|
2966 |
else{
|
| 226 |
liveuser |
2967 |
|
| 3 |
liveuser |
2968 |
#初始化 $j 為 0
|
|
|
2969 |
$wordCount=0;
|
| 226 |
liveuser |
2970 |
|
| 3 |
liveuser |
2971 |
}#else end
|
| 226 |
liveuser |
2972 |
|
| 3 |
liveuser |
2973 |
}#for end
|
| 226 |
liveuser |
2974 |
|
| 3 |
liveuser |
2975 |
#初始化儲存原始的字串
|
|
|
2976 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2977 |
|
| 3 |
liveuser |
2978 |
#初始化處理好的字串
|
|
|
2979 |
$result["content"]="";
|
|
|
2980 |
|
|
|
2981 |
#如果有要剔除的字
|
|
|
2982 |
if($delCount>-1){
|
|
|
2983 |
|
|
|
2984 |
#初始化移除的內容
|
|
|
2985 |
$result["deleted"]="";
|
|
|
2986 |
|
|
|
2987 |
#取得剩下的內容
|
|
|
2988 |
for($i=0;$i<$delCount+1;$i++){
|
| 226 |
liveuser |
2989 |
|
| 3 |
liveuser |
2990 |
#逐字取得字串
|
|
|
2991 |
$result["deleted"]=$result["deleted"].$spiltedStringIn[$i];
|
| 226 |
liveuser |
2992 |
|
| 3 |
liveuser |
2993 |
}#for end
|
|
|
2994 |
|
|
|
2995 |
#取得剩下的內容
|
|
|
2996 |
for($i=$delCount+1;$i<count($spiltedStringIn);$i++){
|
| 226 |
liveuser |
2997 |
|
| 3 |
liveuser |
2998 |
#逐字取得字串
|
|
|
2999 |
$result["content"]=$result["content"].$spiltedStringIn[$i];
|
| 226 |
liveuser |
3000 |
|
| 3 |
liveuser |
3001 |
}#for end
|
| 226 |
liveuser |
3002 |
|
| 3 |
liveuser |
3003 |
#設置有找到關鍵字串
|
|
|
3004 |
$result["founded"]="true";
|
| 226 |
liveuser |
3005 |
|
| 3 |
liveuser |
3006 |
}#if end
|
| 226 |
liveuser |
3007 |
|
| 3 |
liveuser |
3008 |
#反之沒有要處理的字串
|
|
|
3009 |
else{
|
| 226 |
liveuser |
3010 |
|
| 3 |
liveuser |
3011 |
#取得原始字串
|
|
|
3012 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
3013 |
|
| 3 |
liveuser |
3014 |
#設置沒有找到關鍵字串
|
|
|
3015 |
$result["founded"]="false";
|
| 226 |
liveuser |
3016 |
|
| 3 |
liveuser |
3017 |
}#else end
|
| 226 |
liveuser |
3018 |
|
| 3 |
liveuser |
3019 |
#設置執行正常
|
|
|
3020 |
$result["status"]="true";
|
| 226 |
liveuser |
3021 |
|
| 3 |
liveuser |
3022 |
#如果需要遞迴執行
|
|
|
3023 |
if($conf["recursive"]==="true"){
|
| 226 |
liveuser |
3024 |
|
| 3 |
liveuser |
3025 |
#如果沒有找到目標
|
|
|
3026 |
if($result["founded"]==="false"){
|
| 226 |
liveuser |
3027 |
|
| 3 |
liveuser |
3028 |
#如果有前次的結果
|
|
|
3029 |
if(isset($conf["lastResult"])){
|
| 226 |
liveuser |
3030 |
|
| 3 |
liveuser |
3031 |
#回傳之
|
|
|
3032 |
return $conf["lastResult"];
|
| 226 |
liveuser |
3033 |
|
| 3 |
liveuser |
3034 |
}#if enb
|
| 226 |
liveuser |
3035 |
|
| 3 |
liveuser |
3036 |
#回傳本次結果
|
|
|
3037 |
return $result;
|
| 226 |
liveuser |
3038 |
|
| 3 |
liveuser |
3039 |
}#if end
|
| 226 |
liveuser |
3040 |
|
| 3 |
liveuser |
3041 |
#函式說明:
|
|
|
3042 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3043 |
#回傳結果:
|
|
|
3044 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3045 |
#$result["error"],錯誤訊息陣列.
|
|
|
3046 |
#$result["warning"],警告訊息鎮列.
|
|
|
3047 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3048 |
#$result["function"],當前執行的函數名稱.
|
|
|
3049 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
3050 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
3051 |
#必填參數:
|
|
|
3052 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3053 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$result["content"];
|
|
|
3054 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3055 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$conf["keyWord"];
|
|
|
3056 |
#可省略參數:
|
|
|
3057 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
3058 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
3059 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.
|
|
|
3060 |
$conf["stringProcess::delStrBeforeKeyWord"]["lastResult"]=$result;
|
|
|
3061 |
#參考資料:
|
|
|
3062 |
#無.
|
|
|
3063 |
#備註:
|
|
|
3064 |
#無.
|
|
|
3065 |
return stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3066 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3067 |
|
| 3 |
liveuser |
3068 |
}#if end
|
| 226 |
liveuser |
3069 |
|
| 3 |
liveuser |
3070 |
#回傳結果
|
|
|
3071 |
return $result;
|
| 226 |
liveuser |
3072 |
|
| 3 |
liveuser |
3073 |
}#function delStrBeforeKeyWord end
|
|
|
3074 |
|
|
|
3075 |
/*
|
|
|
3076 |
#函式說明:
|
| 249 |
liveuser |
3077 |
#將字串開頭的特定關鍵字移除.
|
|
|
3078 |
#回傳結果:
|
|
|
3079 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3080 |
#$result["error"],錯誤訊息陣列.
|
|
|
3081 |
#$result["founded"],有無找到開頭要移除的特定字串"true"代表有,"false"代表沒有.
|
|
|
3082 |
#$result["function"],當前執行的函數名稱.
|
|
|
3083 |
#$result["argu"],使用的參數.
|
|
|
3084 |
#$result["content"],處理好的的字串內容.
|
|
|
3085 |
#$result["deleted"],被移除的內容.
|
|
|
3086 |
#必填參數:
|
|
|
3087 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3088 |
$conf["stringIn"]="";
|
|
|
3089 |
#$conf["headStr"],字串陣列,開頭為哪些字串就要移除.
|
|
|
3090 |
$conf["headStr"]=array("");
|
|
|
3091 |
#可省略參數:
|
|
|
3092 |
#無.
|
|
|
3093 |
#參考資料:
|
|
|
3094 |
#無.
|
|
|
3095 |
#備註:
|
|
|
3096 |
#無.
|
|
|
3097 |
*/
|
|
|
3098 |
public static function delHeadStr(&$conf){
|
|
|
3099 |
|
|
|
3100 |
#初始化要回傳的結果
|
|
|
3101 |
$result=array();
|
|
|
3102 |
|
|
|
3103 |
#取得當前執行的函數名稱
|
|
|
3104 |
$result["function"]=__FUNCTION__;
|
|
|
3105 |
|
|
|
3106 |
#如果沒有參數
|
|
|
3107 |
if(func_num_args()==0){
|
|
|
3108 |
|
|
|
3109 |
#設置執行失敗
|
|
|
3110 |
$result["status"]="false";
|
|
|
3111 |
|
|
|
3112 |
#設置執行錯誤訊息
|
|
|
3113 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
3114 |
|
|
|
3115 |
#回傳結果
|
|
|
3116 |
return $result;
|
|
|
3117 |
|
|
|
3118 |
}#if end
|
|
|
3119 |
|
|
|
3120 |
/* 請依據實際狀況使用
|
|
|
3121 |
#涵式說明:
|
|
|
3122 |
#判斷當前環境為web還是cmd
|
|
|
3123 |
#回傳結果:
|
|
|
3124 |
#$result,"web"或"cmd"
|
|
|
3125 |
if(csInformation::getEnv()==="web"){
|
|
|
3126 |
|
|
|
3127 |
#設置執行失敗
|
|
|
3128 |
$result["status"]="false";
|
|
|
3129 |
|
|
|
3130 |
#設置執行錯誤訊息
|
|
|
3131 |
$result["error"][]="函數 ".$result["function"]." 僅能在命令列環境下運行!";
|
|
|
3132 |
|
|
|
3133 |
#回傳結果
|
|
|
3134 |
return $result;
|
|
|
3135 |
|
|
|
3136 |
}#if end
|
|
|
3137 |
*/
|
|
|
3138 |
|
|
|
3139 |
#取得參數
|
|
|
3140 |
$result["argu"]=$conf;
|
|
|
3141 |
|
|
|
3142 |
#如果 $conf 不為陣列
|
|
|
3143 |
if(gettype($conf)!=="array"){
|
|
|
3144 |
|
|
|
3145 |
#設置執行失敗
|
|
|
3146 |
$result["status"]="false";
|
|
|
3147 |
|
|
|
3148 |
#設置執行錯誤訊息
|
|
|
3149 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3150 |
|
|
|
3151 |
#如果傳入的參數為 null
|
|
|
3152 |
if(is_null($conf)){
|
|
|
3153 |
|
|
|
3154 |
#設置執行錯誤訊息
|
|
|
3155 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
3156 |
|
|
|
3157 |
}#if end
|
|
|
3158 |
|
|
|
3159 |
#回傳結果
|
|
|
3160 |
return $result;
|
|
|
3161 |
|
|
|
3162 |
}#if end
|
|
|
3163 |
|
|
|
3164 |
#檢查參數
|
|
|
3165 |
#函式說明:
|
|
|
3166 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3167 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3168 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3169 |
#$result["function"],當前執行的函式名稱.
|
|
|
3170 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3171 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3172 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3173 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3174 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3175 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3176 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3177 |
#必填寫的參數:
|
|
|
3178 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3179 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3180 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3181 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","headStr");
|
|
|
3182 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
|
|
3183 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
|
|
|
3184 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3185 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3186 |
#可以省略的參數:
|
|
|
3187 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3188 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3189 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3190 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","lastResult");
|
|
|
3191 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
3192 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array");
|
|
|
3193 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3194 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null);
|
|
|
3195 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3196 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3197 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3198 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
3199 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3200 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("stringIn");
|
|
|
3201 |
#參考資料來源:
|
|
|
3202 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3203 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3204 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3205 |
|
|
|
3206 |
#如果檢查有誤
|
|
|
3207 |
if($checkResult["status"]==="false"){
|
|
|
3208 |
|
|
|
3209 |
#設置錯誤識別
|
|
|
3210 |
$result["status"]="false";
|
|
|
3211 |
|
|
|
3212 |
#設置錯誤訊息
|
|
|
3213 |
$result["error"]=$checkResult;
|
|
|
3214 |
|
|
|
3215 |
#回傳結果
|
|
|
3216 |
return $result;
|
|
|
3217 |
|
|
|
3218 |
}#if end
|
|
|
3219 |
|
|
|
3220 |
#如果檢查不通過
|
|
|
3221 |
if($checkResult["passed"]==="false"){
|
|
|
3222 |
|
|
|
3223 |
#設置錯誤識別
|
|
|
3224 |
$result["status"]="false";
|
|
|
3225 |
|
|
|
3226 |
#設置錯誤訊息
|
|
|
3227 |
$result["error"]=$checkResult;
|
|
|
3228 |
|
|
|
3229 |
#回傳結果
|
|
|
3230 |
return $result;
|
|
|
3231 |
|
|
|
3232 |
}#if end
|
|
|
3233 |
|
|
|
3234 |
#初始化沒有找到要移除的關鍵字
|
|
|
3235 |
$result["founded"]="false";
|
|
|
3236 |
|
|
|
3237 |
#初始化被移除的內容
|
|
|
3238 |
$result["deleted"]="";
|
|
|
3239 |
|
|
|
3240 |
#另存要處理的字串
|
|
|
3241 |
$str2process=$conf["stringIn"];
|
|
|
3242 |
|
|
|
3243 |
#無窮迴圈
|
|
|
3244 |
while(true){
|
|
|
3245 |
|
|
|
3246 |
#預設執行完關鍵字處理一輪後就結束
|
|
|
3247 |
$continue="false";
|
|
|
3248 |
|
|
|
3249 |
#針對每個要移除的開頭字串
|
|
|
3250 |
foreach($conf["headStr"] as $index => $keyWord){
|
|
|
3251 |
|
|
|
3252 |
#函式說明:
|
|
|
3253 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
|
|
3254 |
#回傳結果:
|
|
|
3255 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3256 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3257 |
#$result["function"],當前執行的函式名稱.
|
|
|
3258 |
#$result["argu"],所使用的參數.
|
|
|
3259 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
|
|
3260 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
|
|
3261 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
|
|
3262 |
#必填參數:
|
|
|
3263 |
#$conf["input"],字串,要檢查的字串.
|
|
|
3264 |
$conf["search::findSpecifyStrFormat"]["input"]=$str2process;
|
|
|
3265 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
|
|
3266 |
$conf["search::findSpecifyStrFormat"]["format"]=$keyWord."\${left}";
|
|
|
3267 |
#可省略參數:
|
|
|
3268 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
|
|
3269 |
#$conf["varEqual"]=array(null,"found");
|
|
|
3270 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
|
|
3271 |
#$conf["varCon"]=array("no_tail"=>" not");
|
|
|
3272 |
#參考資料:
|
|
|
3273 |
#無.
|
|
|
3274 |
#備註:
|
|
|
3275 |
#無.
|
|
|
3276 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
|
|
3277 |
unset($conf["search::findSpecifyStrFormat"]);
|
|
|
3278 |
|
|
|
3279 |
#如果執行異常
|
|
|
3280 |
if($findSpecifyStrFormat["status"]==="false"){
|
|
|
3281 |
|
|
|
3282 |
#設置錯誤識別
|
|
|
3283 |
$result["status"]="false";
|
|
|
3284 |
|
|
|
3285 |
#設置錯誤訊息
|
|
|
3286 |
$result["error"]=$findSpecifyStrFormat;
|
|
|
3287 |
|
|
|
3288 |
#回傳結果
|
|
|
3289 |
return $result;
|
|
|
3290 |
|
|
|
3291 |
}#if end
|
|
|
3292 |
|
|
|
3293 |
#如果有找到要移除的關鍵字
|
|
|
3294 |
if($findSpecifyStrFormat["found"]==="true"){
|
|
|
3295 |
|
|
|
3296 |
#串接移除的字串內容
|
|
|
3297 |
$result["deleted"]=$result["deleted"].$keyWord;
|
|
|
3298 |
|
|
|
3299 |
#儲存處理好的結果
|
|
|
3300 |
$str2process=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
|
|
3301 |
|
|
|
3302 |
#設置要繼續執行
|
|
|
3303 |
$continue="true";
|
|
|
3304 |
|
|
|
3305 |
}#if end
|
|
|
3306 |
|
|
|
3307 |
}#foreach end
|
|
|
3308 |
|
|
|
3309 |
#如果沒有必須繼續處理開頭關鍵字了
|
|
|
3310 |
if($continue==="false"){
|
|
|
3311 |
|
|
|
3312 |
#跳出 while
|
|
|
3313 |
break;
|
|
|
3314 |
|
|
|
3315 |
}#if end
|
|
|
3316 |
|
|
|
3317 |
#反之若尚未設置有找到要移除的關鍵字
|
|
|
3318 |
else if($result["founded"]==="false"){
|
|
|
3319 |
|
|
|
3320 |
#設置有找到要移除的關鍵字
|
|
|
3321 |
$result["founded"]="true";
|
|
|
3322 |
|
|
|
3323 |
}#else end
|
|
|
3324 |
|
|
|
3325 |
}#while end
|
|
|
3326 |
|
|
|
3327 |
#儲存處理好的字串
|
|
|
3328 |
$result["content"]=$str2process;
|
|
|
3329 |
|
|
|
3330 |
#設置執行正常
|
|
|
3331 |
$result["status"]="true";
|
|
|
3332 |
|
|
|
3333 |
#回傳結果
|
|
|
3334 |
return $result;
|
|
|
3335 |
|
|
|
3336 |
}#function delHeadStr end
|
|
|
3337 |
|
|
|
3338 |
/*
|
|
|
3339 |
#函式說明:
|
| 3 |
liveuser |
3340 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
3341 |
#回傳結果:
|
|
|
3342 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3343 |
#$result["error"],錯誤訊息陣列.
|
|
|
3344 |
#$result["warning"],警告訊息鎮列.
|
|
|
3345 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3346 |
#$result["function"],當前執行的函數名稱.
|
|
|
3347 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3348 |
#$result["content"],處理好的的字串內容.
|
|
|
3349 |
#$result["deleted"],被移除的內容.
|
|
|
3350 |
#$result["argu"],使用的參數.
|
|
|
3351 |
#必填參數:
|
|
|
3352 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3353 |
$conf["stringIn"]="";
|
|
|
3354 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3355 |
$conf["keyWord"]="";
|
|
|
3356 |
#可省略參數:
|
|
|
3357 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
3358 |
#$conf["deleteLastRepeatedOne"]="";
|
|
|
3359 |
#參考資料:
|
|
|
3360 |
#無.
|
|
|
3361 |
#備註:
|
|
|
3362 |
#無.
|
|
|
3363 |
*/
|
|
|
3364 |
public static function delStrAfterKeyWord(&$conf){
|
| 226 |
liveuser |
3365 |
|
| 3 |
liveuser |
3366 |
#初始化要回傳的內容
|
|
|
3367 |
$result=array();
|
|
|
3368 |
|
|
|
3369 |
#取得當前執行的函數名稱
|
|
|
3370 |
$result["function"]=__FUNCTION__;
|
|
|
3371 |
|
|
|
3372 |
#如果 $conf 不為陣列
|
|
|
3373 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
3374 |
|
| 3 |
liveuser |
3375 |
#設置執行失敗
|
|
|
3376 |
$result["status"]="false";
|
| 226 |
liveuser |
3377 |
|
| 3 |
liveuser |
3378 |
#設置執行錯誤訊息
|
|
|
3379 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3380 |
|
|
|
3381 |
#如果傳入的參數為 null
|
|
|
3382 |
if($conf==null){
|
| 226 |
liveuser |
3383 |
|
| 3 |
liveuser |
3384 |
#設置執行錯誤訊息
|
|
|
3385 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3386 |
|
| 3 |
liveuser |
3387 |
}#if end
|
|
|
3388 |
|
|
|
3389 |
#回傳結果
|
|
|
3390 |
return $result;
|
| 226 |
liveuser |
3391 |
|
| 3 |
liveuser |
3392 |
}#if end
|
|
|
3393 |
|
|
|
3394 |
#檢查參數
|
|
|
3395 |
#函式說明:
|
|
|
3396 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3397 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3398 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3399 |
#$result["function"],當前執行的函式名稱.
|
|
|
3400 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3401 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3402 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3403 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3404 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3405 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3406 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3407 |
#必填寫的參數:
|
|
|
3408 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3409 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3410 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3411 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","keyWord");
|
| 226 |
liveuser |
3412 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
3413 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3414 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3415 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3416 |
#可以省略的參數:
|
|
|
3417 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3418 |
#$conf["canBeEmptyString"]="false";
|
|
|
3419 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3420 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("deleteLastRepeatedOne");
|
| 226 |
liveuser |
3421 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
3422 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
3423 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3424 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
3425 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3426 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3427 |
#參考資料來源:
|
|
|
3428 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3429 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3430 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3431 |
|
|
|
3432 |
#如果檢查有誤
|
|
|
3433 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
3434 |
|
| 3 |
liveuser |
3435 |
#設置錯誤識別
|
|
|
3436 |
$result["status"]="false";
|
| 226 |
liveuser |
3437 |
|
| 3 |
liveuser |
3438 |
#設置錯誤訊息
|
|
|
3439 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3440 |
|
| 3 |
liveuser |
3441 |
#回傳結果
|
|
|
3442 |
return $result;
|
| 226 |
liveuser |
3443 |
|
| 3 |
liveuser |
3444 |
}#if end
|
| 226 |
liveuser |
3445 |
|
| 3 |
liveuser |
3446 |
#如果檢查不通過
|
|
|
3447 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
3448 |
|
| 3 |
liveuser |
3449 |
#設置錯誤識別
|
|
|
3450 |
$result["status"]="false";
|
| 226 |
liveuser |
3451 |
|
| 3 |
liveuser |
3452 |
#設置錯誤訊息
|
|
|
3453 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3454 |
|
| 3 |
liveuser |
3455 |
#回傳結果
|
|
|
3456 |
return $result;
|
| 226 |
liveuser |
3457 |
|
| 3 |
liveuser |
3458 |
}#if end
|
| 226 |
liveuser |
3459 |
|
| 3 |
liveuser |
3460 |
#記錄使用的參數
|
|
|
3461 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
3462 |
|
| 3 |
liveuser |
3463 |
#倒序內容
|
|
|
3464 |
$conf["stringIn"]=strrev($conf["stringIn"]);
|
| 226 |
liveuser |
3465 |
|
| 3 |
liveuser |
3466 |
#倒敘關鍵字
|
|
|
3467 |
$conf["keyWord"]=strrev($conf["keyWord"]);
|
| 226 |
liveuser |
3468 |
|
| 3 |
liveuser |
3469 |
#函式說明:
|
|
|
3470 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3471 |
#回傳結果:
|
|
|
3472 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3473 |
#$result["error"],錯誤訊息陣列.
|
|
|
3474 |
#$result["warning"],警告訊息鎮列.
|
|
|
3475 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3476 |
#$result["function"],當前執行的函數名稱.
|
|
|
3477 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
3478 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
3479 |
#必填參數:
|
|
|
3480 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3481 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["stringIn"];
|
|
|
3482 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3483 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$conf["keyWord"];
|
|
|
3484 |
#可省略參數:
|
| 226 |
liveuser |
3485 |
|
| 3 |
liveuser |
3486 |
#如果不需要移除最後一個符合的關鍵字之後的內容
|
|
|
3487 |
if($conf["deleteLastRepeatedOne"]==="false"){
|
| 226 |
liveuser |
3488 |
|
| 3 |
liveuser |
3489 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
3490 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
| 226 |
liveuser |
3491 |
|
| 3 |
liveuser |
3492 |
}#if end
|
| 226 |
liveuser |
3493 |
|
| 3 |
liveuser |
3494 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.
|
|
|
3495 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
3496 |
#參考資料:
|
|
|
3497 |
#無.
|
|
|
3498 |
#備註:
|
|
|
3499 |
#無.
|
|
|
3500 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3501 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3502 |
|
| 3 |
liveuser |
3503 |
#如果執行失敗
|
|
|
3504 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
3505 |
|
| 3 |
liveuser |
3506 |
#設置錯誤識別
|
|
|
3507 |
$result["status"]="false";
|
| 226 |
liveuser |
3508 |
|
| 3 |
liveuser |
3509 |
#設置錯誤訊息
|
|
|
3510 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
3511 |
|
| 3 |
liveuser |
3512 |
#回傳結果
|
|
|
3513 |
return $result;
|
| 226 |
liveuser |
3514 |
|
| 3 |
liveuser |
3515 |
}#if end
|
| 226 |
liveuser |
3516 |
|
| 3 |
liveuser |
3517 |
#如果沒有關鍵字
|
|
|
3518 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
3519 |
|
| 3 |
liveuser |
3520 |
#設置執行正常
|
|
|
3521 |
$result["status"]="true";
|
| 226 |
liveuser |
3522 |
|
| 3 |
liveuser |
3523 |
#設置沒有找到關鍵字
|
|
|
3524 |
$result["founded"]="false";
|
| 226 |
liveuser |
3525 |
|
| 3 |
liveuser |
3526 |
#初始化儲存原始的字串
|
|
|
3527 |
$result["oriStr"]=strrev($delStrBeforeKeyWord["oriStr"]);
|
| 226 |
liveuser |
3528 |
|
| 3 |
liveuser |
3529 |
#取得移除後的結果
|
|
|
3530 |
$result["content"]=strrev($delStrBeforeKeyWord["content"]);
|
| 226 |
liveuser |
3531 |
|
| 3 |
liveuser |
3532 |
#回傳結果
|
|
|
3533 |
return $result;
|
| 226 |
liveuser |
3534 |
|
| 3 |
liveuser |
3535 |
}#if end
|
| 226 |
liveuser |
3536 |
|
| 3 |
liveuser |
3537 |
#設置執行正常
|
|
|
3538 |
$result["status"]="true";
|
| 226 |
liveuser |
3539 |
|
| 3 |
liveuser |
3540 |
#設置有找到關鍵字
|
|
|
3541 |
$result["founded"]="true";
|
| 226 |
liveuser |
3542 |
|
| 3 |
liveuser |
3543 |
#初始化儲存原始的字串
|
|
|
3544 |
$result["oriStr"]=strrev($conf["stringIn"]);
|
| 226 |
liveuser |
3545 |
|
| 3 |
liveuser |
3546 |
#取得移除後的結果
|
|
|
3547 |
$result["content"]=strrev($delStrBeforeKeyWord["content"]);
|
| 226 |
liveuser |
3548 |
|
| 3 |
liveuser |
3549 |
#取得被移除的內容
|
|
|
3550 |
$result["deleted"]=strrev($delStrBeforeKeyWord["deleted"]);
|
| 226 |
liveuser |
3551 |
|
| 3 |
liveuser |
3552 |
#回傳結果
|
|
|
3553 |
return $result;
|
| 226 |
liveuser |
3554 |
|
| 3 |
liveuser |
3555 |
}#function delStrAfterKeyWord end
|
|
|
3556 |
|
|
|
3557 |
/*
|
|
|
3558 |
#函式說明:
|
|
|
3559 |
#移除多個字串開頭相同的部分
|
|
|
3560 |
#回傳結果:
|
|
|
3561 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3562 |
#$result["error"],錯誤訊息陣列.
|
|
|
3563 |
#$result["function"],當前執行的函數名稱.
|
|
|
3564 |
#$result["content"],處理好的的字串內容.
|
|
|
3565 |
#必填參數:
|
|
|
3566 |
#$conf["strIn"],字串陣列,每個要處理的字串.
|
| 226 |
liveuser |
3567 |
$conf["strIn"]=array();
|
| 3 |
liveuser |
3568 |
#可省略參數:
|
|
|
3569 |
#無.
|
|
|
3570 |
#參考資料:
|
|
|
3571 |
#無.
|
|
|
3572 |
#備註:
|
|
|
3573 |
#無.
|
|
|
3574 |
*/
|
|
|
3575 |
public static function delSameHead(&$conf){
|
| 226 |
liveuser |
3576 |
|
| 3 |
liveuser |
3577 |
#初始化要回傳的內容
|
|
|
3578 |
$result=array();
|
|
|
3579 |
|
|
|
3580 |
#取得當前執行的函數名稱
|
|
|
3581 |
$result["function"]=__FUNCTION__;
|
|
|
3582 |
|
|
|
3583 |
#如果 $conf 不為陣列
|
|
|
3584 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
3585 |
|
| 3 |
liveuser |
3586 |
#設置執行失敗
|
|
|
3587 |
$result["status"]="false";
|
| 226 |
liveuser |
3588 |
|
| 3 |
liveuser |
3589 |
#設置執行錯誤訊息
|
|
|
3590 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3591 |
|
|
|
3592 |
#如果傳入的參數為 null
|
|
|
3593 |
if($conf==null){
|
| 226 |
liveuser |
3594 |
|
| 3 |
liveuser |
3595 |
#設置執行錯誤訊息
|
|
|
3596 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3597 |
|
| 3 |
liveuser |
3598 |
}#if end
|
|
|
3599 |
|
|
|
3600 |
#回傳結果
|
|
|
3601 |
return $result;
|
| 226 |
liveuser |
3602 |
|
| 3 |
liveuser |
3603 |
}#if end
|
| 226 |
liveuser |
3604 |
|
| 3 |
liveuser |
3605 |
#函式說明:
|
|
|
3606 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3607 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3608 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3609 |
#$result["function"],當前執行的函式名稱.
|
|
|
3610 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3611 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3612 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3613 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3614 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3615 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3616 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3617 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3618 |
#必填寫的參數:
|
|
|
3619 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3620 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3621 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3622 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("strIn");
|
|
|
3623 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3624 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
3625 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3626 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3627 |
#可以省略的參數:
|
|
|
3628 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3629 |
#$conf["canBeEmptyString"]="false";
|
|
|
3630 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
3631 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3632 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3633 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
3634 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
3635 |
#$conf["skipableVariableType"]=array();
|
|
|
3636 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3637 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
3638 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3639 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3640 |
#參考資料來源:
|
|
|
3641 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3642 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
3643 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3644 |
|
| 3 |
liveuser |
3645 |
#初始化儲存開頭相同的字串
|
| 226 |
liveuser |
3646 |
$sameHeadStr="";
|
|
|
3647 |
|
|
|
3648 |
#$conf["strIn"]的第一個元素有幾個字就執行幾次
|
| 3 |
liveuser |
3649 |
for($i=0;$i<strlen($conf["strIn"][0]);$i++){
|
| 226 |
liveuser |
3650 |
|
| 3 |
liveuser |
3651 |
#取得當前可能相同的開頭字串
|
|
|
3652 |
$keyWordPart=$sameHeadStr.$conf["strIn"][0][$i];
|
| 226 |
liveuser |
3653 |
|
| 3 |
liveuser |
3654 |
#函式說明:
|
|
|
3655 |
#取得多個符合特定字首與字尾的字串.
|
|
|
3656 |
#回傳結果:
|
|
|
3657 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
3658 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
3659 |
#$result["function"],當前執行的函數名稱.
|
|
|
3660 |
#$result["returnString"],爲符合字首條件的字串陣列內容。
|
|
|
3661 |
#必填參數:
|
|
|
3662 |
#$conf["checkString"],陣列字串,要檢查的字串們.
|
|
|
3663 |
$conf["search::getMeetConditionsStringMulti"]["checkString"]=$conf["strIn"];#要檢查的字串陣列
|
|
|
3664 |
#可省略參數:
|
|
|
3665 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
3666 |
$conf["search::getMeetConditionsStringMulti"]["frontWord"]=$keyWordPart;
|
|
|
3667 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
3668 |
#$conf["tailWord"]="";
|
|
|
3669 |
#參考資料:
|
|
|
3670 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
3671 |
$checkResult=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
|
|
|
3672 |
unset($conf["search::getMeetConditionsStringMulti"]);
|
| 226 |
liveuser |
3673 |
|
| 3 |
liveuser |
3674 |
#如果執行失敗
|
|
|
3675 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
3676 |
|
| 3 |
liveuser |
3677 |
#設置執行失敗
|
|
|
3678 |
$result["status"]="false";
|
| 226 |
liveuser |
3679 |
|
| 3 |
liveuser |
3680 |
#設置執行錯誤訊息
|
|
|
3681 |
$result["error"]=$checkResult;
|
|
|
3682 |
|
|
|
3683 |
#回傳結果
|
|
|
3684 |
return $result;
|
| 226 |
liveuser |
3685 |
|
| 3 |
liveuser |
3686 |
}#if end
|
| 226 |
liveuser |
3687 |
|
| 3 |
liveuser |
3688 |
#如果有找到相同的開頭
|
|
|
3689 |
if($checkResult["founded"]=="true"){
|
| 226 |
liveuser |
3690 |
|
| 3 |
liveuser |
3691 |
#取得新的開頭相同字串內容
|
|
|
3692 |
$sameHeadStr=$keyWordPart;
|
| 226 |
liveuser |
3693 |
|
| 3 |
liveuser |
3694 |
}#if end
|
| 226 |
liveuser |
3695 |
|
| 3 |
liveuser |
3696 |
#反之
|
|
|
3697 |
else{
|
| 226 |
liveuser |
3698 |
|
| 3 |
liveuser |
3699 |
#跳出迴圈
|
|
|
3700 |
break;
|
| 226 |
liveuser |
3701 |
|
| 3 |
liveuser |
3702 |
}#else end
|
| 226 |
liveuser |
3703 |
|
| 3 |
liveuser |
3704 |
}#for end
|
| 226 |
liveuser |
3705 |
|
|
|
3706 |
#$conf["strIn"]有幾個元素就執行幾次
|
| 3 |
liveuser |
3707 |
for($i=0;$i<count($conf["strIn"]);$i++){
|
| 226 |
liveuser |
3708 |
|
| 3 |
liveuser |
3709 |
#移除 $conf["strIn"] 中每個字串開頭相同的部分
|
|
|
3710 |
#函式說明:
|
|
|
3711 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3712 |
#回傳結果:
|
|
|
3713 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3714 |
#$result["error"],錯誤訊息陣列.
|
|
|
3715 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3716 |
#$result["function"],當前執行的函數名稱.
|
|
|
3717 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3718 |
#$result["content"],處理好的的字串內容.
|
|
|
3719 |
#必填參數:
|
|
|
3720 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["strIn"][$i];#要處理的字串.
|
|
|
3721 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$sameHeadStr;#特定字串.
|
|
|
3722 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3723 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3724 |
|
| 3 |
liveuser |
3725 |
#如果執行失敗
|
|
|
3726 |
if($delStrBeforeKeyWord["status"]=="false"){
|
| 226 |
liveuser |
3727 |
|
| 3 |
liveuser |
3728 |
#設置執行失敗
|
|
|
3729 |
$result["status"]="false";
|
| 226 |
liveuser |
3730 |
|
| 3 |
liveuser |
3731 |
#設置執行錯誤訊息
|
|
|
3732 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
3733 |
|
|
|
3734 |
#回傳結果
|
|
|
3735 |
return $result;
|
| 226 |
liveuser |
3736 |
|
| 3 |
liveuser |
3737 |
}#if end
|
| 226 |
liveuser |
3738 |
|
|
|
3739 |
#取得處理好的字串
|
| 3 |
liveuser |
3740 |
$result["content"][]=$delStrBeforeKeyWord["content"];
|
| 226 |
liveuser |
3741 |
|
| 3 |
liveuser |
3742 |
}#for end
|
| 226 |
liveuser |
3743 |
|
| 3 |
liveuser |
3744 |
#設置執行正常
|
|
|
3745 |
$result["status"]="true";
|
| 226 |
liveuser |
3746 |
|
| 3 |
liveuser |
3747 |
#回傳結果
|
|
|
3748 |
return $result;
|
| 226 |
liveuser |
3749 |
|
| 3 |
liveuser |
3750 |
}#function delSameHead end
|
| 226 |
liveuser |
3751 |
|
| 3 |
liveuser |
3752 |
/*
|
|
|
3753 |
#函式說明:
|
|
|
3754 |
#移除字串開頭的特定內容
|
|
|
3755 |
#回傳結果:
|
|
|
3756 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
3757 |
#$result["error"],錯誤訊息陣列.
|
|
|
3758 |
#$result["function"],當前執行的函數.
|
|
|
3759 |
#$result["content"],處理好的字串.
|
|
|
3760 |
#$result["argu"],使用的參數.
|
|
|
3761 |
#必填參數:
|
|
|
3762 |
#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
|
|
|
3763 |
$conf["inputStr"]="";
|
|
|
3764 |
#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
|
| 226 |
liveuser |
3765 |
$conf["keyWord"]="";
|
| 3 |
liveuser |
3766 |
#可省略參數:
|
|
|
3767 |
#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
|
|
|
3768 |
#$conf["recursive"]="false";
|
|
|
3769 |
#參考資料:
|
|
|
3770 |
#無.
|
|
|
3771 |
#備註:
|
|
|
3772 |
#無.
|
|
|
3773 |
*/
|
|
|
3774 |
public static function delKeyWordsInStrHead(&$conf){
|
| 226 |
liveuser |
3775 |
|
| 3 |
liveuser |
3776 |
#初始化要回傳的結果
|
|
|
3777 |
$result=array();
|
|
|
3778 |
|
|
|
3779 |
#初始化要回傳的結果
|
|
|
3780 |
$result["content"]="";
|
|
|
3781 |
|
|
|
3782 |
#儲存當前執行的函數
|
|
|
3783 |
$result["function"]=__FUNCTION__;
|
|
|
3784 |
|
|
|
3785 |
#如果 $conf 不為陣列
|
|
|
3786 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
3787 |
|
| 3 |
liveuser |
3788 |
#設置執行失敗
|
|
|
3789 |
$result["status"]="false";
|
| 226 |
liveuser |
3790 |
|
| 3 |
liveuser |
3791 |
#設置執行錯誤訊息
|
|
|
3792 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3793 |
|
|
|
3794 |
#如果傳入的參數為 null
|
|
|
3795 |
if($conf==null){
|
| 226 |
liveuser |
3796 |
|
| 3 |
liveuser |
3797 |
#設置執行錯誤訊息
|
|
|
3798 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3799 |
|
| 3 |
liveuser |
3800 |
}#if end
|
|
|
3801 |
|
|
|
3802 |
#回傳結果
|
|
|
3803 |
return $result;
|
| 226 |
liveuser |
3804 |
|
| 3 |
liveuser |
3805 |
}#if end
|
| 226 |
liveuser |
3806 |
|
| 3 |
liveuser |
3807 |
#記錄參數
|
|
|
3808 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
3809 |
|
| 3 |
liveuser |
3810 |
#檢查參數
|
|
|
3811 |
#函式說明:
|
|
|
3812 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3813 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3814 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3815 |
#$result["function"],當前執行的函式名稱.
|
|
|
3816 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3817 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3818 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3819 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3820 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3821 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3822 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3823 |
#必填寫的參數:
|
|
|
3824 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3825 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3826 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3827 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("inputStr","keyWord");
|
| 226 |
liveuser |
3828 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
3829 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3830 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3831 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3832 |
#可以省略的參數:
|
|
|
3833 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
3834 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3835 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3836 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive");
|
| 226 |
liveuser |
3837 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
3838 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
3839 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3840 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
3841 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3842 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
|
|
|
3843 |
#參考資料來源:
|
|
|
3844 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3845 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3846 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
3847 |
|
| 3 |
liveuser |
3848 |
#如果檢查失敗
|
|
|
3849 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
3850 |
|
| 3 |
liveuser |
3851 |
#設置錯誤識別
|
|
|
3852 |
$result["status"]="false";
|
| 226 |
liveuser |
3853 |
|
| 3 |
liveuser |
3854 |
#設置錯誤訊息
|
|
|
3855 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3856 |
|
| 3 |
liveuser |
3857 |
#回傳結果
|
|
|
3858 |
return $result;
|
| 226 |
liveuser |
3859 |
|
| 3 |
liveuser |
3860 |
}#if end
|
| 226 |
liveuser |
3861 |
|
| 3 |
liveuser |
3862 |
#如果檢查不通過
|
|
|
3863 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
3864 |
|
| 3 |
liveuser |
3865 |
#設置錯誤識別
|
|
|
3866 |
$result["status"]="false";
|
| 226 |
liveuser |
3867 |
|
| 3 |
liveuser |
3868 |
#設置錯誤訊息
|
|
|
3869 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3870 |
|
| 3 |
liveuser |
3871 |
#回傳結果
|
|
|
3872 |
return $result;
|
| 226 |
liveuser |
3873 |
|
| 3 |
liveuser |
3874 |
}#if end
|
| 226 |
liveuser |
3875 |
|
| 3 |
liveuser |
3876 |
#取得關鍵字的位置
|
|
|
3877 |
$found=strpos($conf["inputStr"],$conf["keyWord"]);
|
| 226 |
liveuser |
3878 |
|
| 3 |
liveuser |
3879 |
#debug
|
|
|
3880 |
#var_dump($conf["inputStr"],$conf["keyWord"],$found);
|
| 226 |
liveuser |
3881 |
|
| 3 |
liveuser |
3882 |
#如果沒有找到關鍵字
|
|
|
3883 |
if($found===false){
|
| 226 |
liveuser |
3884 |
|
| 3 |
liveuser |
3885 |
#設置執行正常
|
|
|
3886 |
$result["status"]="true";
|
| 226 |
liveuser |
3887 |
|
| 3 |
liveuser |
3888 |
#設置處理好的字串
|
|
|
3889 |
$result["content"]=$conf["inputStr"];
|
| 226 |
liveuser |
3890 |
|
| 3 |
liveuser |
3891 |
#回傳結果
|
|
|
3892 |
return $result;
|
| 226 |
liveuser |
3893 |
|
| 3 |
liveuser |
3894 |
}#if end
|
| 226 |
liveuser |
3895 |
|
| 3 |
liveuser |
3896 |
#如果關鍵字在開頭
|
|
|
3897 |
else if($found===0){
|
| 226 |
liveuser |
3898 |
|
| 3 |
liveuser |
3899 |
#分割字串
|
|
|
3900 |
$spiledStr=str_split($conf["inputStr"]);
|
| 226 |
liveuser |
3901 |
|
| 3 |
liveuser |
3902 |
#執行 count($spiledStr)-2 次迴圈
|
|
|
3903 |
for($i=strlen($conf["keyWord"]);$i<count($spiledStr);$i++){
|
| 226 |
liveuser |
3904 |
|
| 3 |
liveuser |
3905 |
#串接字
|
|
|
3906 |
$result["content"]=$result["content"].$spiledStr[$i];
|
| 226 |
liveuser |
3907 |
|
| 3 |
liveuser |
3908 |
}#for end
|
| 226 |
liveuser |
3909 |
|
| 3 |
liveuser |
3910 |
#設置執行正常
|
|
|
3911 |
$result["status"]="true";
|
| 226 |
liveuser |
3912 |
|
| 3 |
liveuser |
3913 |
#如果有開啟遞迴
|
|
|
3914 |
if($conf["recursive"]==="true"){
|
| 226 |
liveuser |
3915 |
|
| 3 |
liveuser |
3916 |
#函式說明:
|
|
|
3917 |
#移除字串開頭的特定內容
|
|
|
3918 |
#回傳結果:
|
|
|
3919 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
3920 |
#$result["error"],錯誤訊息陣列.
|
|
|
3921 |
#$result["function"],當前執行的函數.
|
|
|
3922 |
#$result["content"],處理好的字串.
|
|
|
3923 |
#必填參數:
|
|
|
3924 |
#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
|
|
|
3925 |
$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$result["content"];
|
|
|
3926 |
#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
|
| 226 |
liveuser |
3927 |
$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]=$conf["keyWord"];
|
| 3 |
liveuser |
3928 |
#可省略參數:
|
|
|
3929 |
#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
|
|
|
3930 |
$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
|
| 226 |
liveuser |
3931 |
return stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
|
|
|
3932 |
unset($conf["stringProcess::delKeyWordsInStrHead"]);
|
|
|
3933 |
|
| 3 |
liveuser |
3934 |
}#if end
|
| 226 |
liveuser |
3935 |
|
| 3 |
liveuser |
3936 |
#回傳結果
|
|
|
3937 |
return $result;
|
| 226 |
liveuser |
3938 |
|
| 3 |
liveuser |
3939 |
}#if end
|
| 226 |
liveuser |
3940 |
|
|
|
3941 |
#反之關鍵字不在開頭
|
| 3 |
liveuser |
3942 |
else{
|
| 226 |
liveuser |
3943 |
|
| 3 |
liveuser |
3944 |
#設置執行正常
|
|
|
3945 |
$result["status"]="true";
|
| 226 |
liveuser |
3946 |
|
| 3 |
liveuser |
3947 |
#設置處理好的字串
|
|
|
3948 |
$result["content"]=$conf["inputStr"];
|
| 226 |
liveuser |
3949 |
|
| 3 |
liveuser |
3950 |
#回傳結果
|
|
|
3951 |
return $result;
|
| 226 |
liveuser |
3952 |
|
| 3 |
liveuser |
3953 |
}#else end
|
| 226 |
liveuser |
3954 |
|
| 3 |
liveuser |
3955 |
#執行到這邊代表不正常
|
| 226 |
liveuser |
3956 |
|
| 3 |
liveuser |
3957 |
#設置錯誤識別
|
|
|
3958 |
$result["status"]="false";
|
| 226 |
liveuser |
3959 |
|
| 3 |
liveuser |
3960 |
#設置錯誤訊息
|
|
|
3961 |
$result["error"][]="非預期的錯誤";
|
| 226 |
liveuser |
3962 |
|
| 3 |
liveuser |
3963 |
#回傳結果
|
|
|
3964 |
return $result;
|
| 226 |
liveuser |
3965 |
|
| 3 |
liveuser |
3966 |
}#function delKeyWordsInStrHead end
|
|
|
3967 |
|
|
|
3968 |
/*
|
|
|
3969 |
#函式說明:
|
|
|
3970 |
#將字串進行解析,取得兩個關鍵字中間的內容.
|
|
|
3971 |
#回傳結果:
|
|
|
3972 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
3973 |
#$result["function"],當前執行的函式內容.
|
|
|
3974 |
#$result["error"],錯誤訊息陣列.
|
|
|
3975 |
#$result["content"],取得的內容.
|
|
|
3976 |
#$result["oriStr"],原始的內容.
|
|
|
3977 |
#$result["found"],是否有找到符合條件的內容.
|
|
|
3978 |
#必填參數:
|
|
|
3979 |
#$conf["input"],字串,要處理的字串.
|
|
|
3980 |
$conf["input"]="";
|
|
|
3981 |
#$conf["startKeyWord"],字串,開頭的關鍵字.
|
|
|
3982 |
$conf["startKeyWord"]="";
|
|
|
3983 |
#$conf["endKeyWord"],字串,結束的關鍵字.
|
|
|
3984 |
$conf["endKeyWord"]="";
|
|
|
3985 |
#可省略參數:
|
|
|
3986 |
#無.
|
|
|
3987 |
#參考資料:
|
|
|
3988 |
#無.
|
|
|
3989 |
#備註:
|
|
|
3990 |
#無.
|
|
|
3991 |
*/
|
|
|
3992 |
public static function getContentBetweenKeyWord(&$conf){
|
| 226 |
liveuser |
3993 |
|
| 3 |
liveuser |
3994 |
#初始化要回傳的結果
|
|
|
3995 |
$result=array();
|
|
|
3996 |
|
|
|
3997 |
#取得當前執行的函數名稱
|
|
|
3998 |
$result["function"]=__FUNCTION__;
|
|
|
3999 |
|
|
|
4000 |
#如果沒有參數
|
|
|
4001 |
if(func_num_args()==0){
|
| 226 |
liveuser |
4002 |
|
| 3 |
liveuser |
4003 |
#設置執行失敗
|
|
|
4004 |
$result["status"]="false";
|
| 226 |
liveuser |
4005 |
|
| 3 |
liveuser |
4006 |
#設置執行錯誤訊息
|
|
|
4007 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
4008 |
|
| 3 |
liveuser |
4009 |
#回傳結果
|
|
|
4010 |
return $result;
|
| 226 |
liveuser |
4011 |
|
| 3 |
liveuser |
4012 |
}#if end
|
|
|
4013 |
|
|
|
4014 |
#取得參數
|
|
|
4015 |
$result["argu"]=$conf;
|
|
|
4016 |
|
|
|
4017 |
#如果 $conf 不為陣列
|
|
|
4018 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
4019 |
|
| 3 |
liveuser |
4020 |
#設置執行失敗
|
|
|
4021 |
$result["status"]="false";
|
| 226 |
liveuser |
4022 |
|
| 3 |
liveuser |
4023 |
#設置執行錯誤訊息
|
|
|
4024 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
4025 |
|
| 3 |
liveuser |
4026 |
#如果傳入的參數為 null
|
|
|
4027 |
if($conf===null){
|
| 226 |
liveuser |
4028 |
|
| 3 |
liveuser |
4029 |
#設置執行錯誤訊息
|
|
|
4030 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4031 |
|
| 3 |
liveuser |
4032 |
}#if end
|
|
|
4033 |
|
|
|
4034 |
#回傳結果
|
|
|
4035 |
return $result;
|
| 226 |
liveuser |
4036 |
|
| 3 |
liveuser |
4037 |
}#if end
|
| 226 |
liveuser |
4038 |
|
| 3 |
liveuser |
4039 |
#函式說明:
|
|
|
4040 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4041 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4042 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4043 |
#$result["function"],當前執行的函式名稱.
|
|
|
4044 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4045 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4046 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4047 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4048 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4049 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4050 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4051 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4052 |
#必填寫的參數:
|
|
|
4053 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4054 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4055 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4056 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","startKeyWord","endKeyWord");
|
|
|
4057 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4058 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
4059 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4060 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4061 |
#可以省略的參數:
|
|
|
4062 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4063 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
4064 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4065 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4066 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4067 |
#$conf["canBeEmpty"]=array();
|
|
|
4068 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4069 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4070 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4071 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
4072 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4073 |
#$conf["skipableVariableType"]=array();
|
|
|
4074 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4075 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4076 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4077 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4078 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4079 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4080 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4081 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4082 |
#參考資料來源:
|
|
|
4083 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4084 |
#建議:
|
|
|
4085 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4086 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4087 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4088 |
|
| 3 |
liveuser |
4089 |
#如果檢查參數失敗
|
|
|
4090 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
4091 |
|
| 3 |
liveuser |
4092 |
#設置執行失敗
|
|
|
4093 |
$result["status"]="false";
|
| 226 |
liveuser |
4094 |
|
| 3 |
liveuser |
4095 |
#設置執行錯誤訊息
|
|
|
4096 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4097 |
|
| 3 |
liveuser |
4098 |
#回傳結果
|
|
|
4099 |
return $result;
|
| 226 |
liveuser |
4100 |
|
| 3 |
liveuser |
4101 |
}#if end
|
| 226 |
liveuser |
4102 |
|
| 3 |
liveuser |
4103 |
#如果檢查參數不通過
|
|
|
4104 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4105 |
|
| 3 |
liveuser |
4106 |
#設置執行失敗
|
|
|
4107 |
$result["status"]="false";
|
| 226 |
liveuser |
4108 |
|
| 3 |
liveuser |
4109 |
#設置執行錯誤訊息
|
|
|
4110 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4111 |
|
| 3 |
liveuser |
4112 |
#回傳結果
|
|
|
4113 |
return $result;
|
| 226 |
liveuser |
4114 |
|
| 3 |
liveuser |
4115 |
}#if end
|
| 226 |
liveuser |
4116 |
|
| 3 |
liveuser |
4117 |
#檢查是否有符合的關鍵字存在
|
|
|
4118 |
#函式說明:
|
|
|
4119 |
#檢查一個字串裡面是否有多個關鍵字
|
|
|
4120 |
#回傳結果:
|
|
|
4121 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗.
|
|
|
4122 |
#$result["error"],錯誤訊息.
|
|
|
4123 |
#$result["function"],當前執行的函數名稱.
|
|
|
4124 |
#$result["founded"],是否有找到的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字.
|
|
|
4125 |
#$result["foundedKeyWords"],找到的關鍵字.
|
|
|
4126 |
#$result["foundedAll"],是否有找到全部的關鍵字,"true"代表有;"false"代表沒有.
|
|
|
4127 |
#$result["argu"],使用的參數.
|
|
|
4128 |
#必填參數:
|
|
|
4129 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
4130 |
$conf["search::findManyKeyWords"]["keyWords"]=array($conf["startKeyWord"],$conf["endKeyWord"]);
|
|
|
4131 |
#$conf["string"],字串,要被搜尋的字串內容.
|
|
|
4132 |
$conf["search::findManyKeyWords"]["string"]=$conf["input"];
|
|
|
4133 |
#可省略參數:
|
|
|
4134 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合.
|
|
|
4135 |
#$conf["completeEqual"]="true";
|
|
|
4136 |
#參考資料:
|
|
|
4137 |
#無.
|
|
|
4138 |
#備註:
|
|
|
4139 |
#無.
|
|
|
4140 |
$findManyKeyWords=search::findManyKeyWords($conf["search::findManyKeyWords"]);
|
|
|
4141 |
unset($conf["search::findManyKeyWords"]);
|
| 226 |
liveuser |
4142 |
|
| 3 |
liveuser |
4143 |
#如果執行失敗
|
|
|
4144 |
if($findManyKeyWords["status"]==="false"){
|
| 226 |
liveuser |
4145 |
|
| 3 |
liveuser |
4146 |
#設置執行失敗
|
|
|
4147 |
$result["status"]="false";
|
| 226 |
liveuser |
4148 |
|
| 3 |
liveuser |
4149 |
#設置執行錯誤訊息
|
|
|
4150 |
$result["error"]=$findManyKeyWords;
|
| 226 |
liveuser |
4151 |
|
| 3 |
liveuser |
4152 |
#回傳結果
|
|
|
4153 |
return $result;
|
| 226 |
liveuser |
4154 |
|
| 3 |
liveuser |
4155 |
}#if end
|
| 226 |
liveuser |
4156 |
|
| 3 |
liveuser |
4157 |
#設置預設有找到關鍵字
|
|
|
4158 |
$result["found"]="true";
|
| 226 |
liveuser |
4159 |
|
| 3 |
liveuser |
4160 |
#如果沒有找到全部關鍵字
|
|
|
4161 |
if($findManyKeyWords["foundedAll"]==="false"){
|
| 226 |
liveuser |
4162 |
|
| 3 |
liveuser |
4163 |
#設置沒有找到關鍵字
|
|
|
4164 |
$result["found"]="false";
|
| 226 |
liveuser |
4165 |
|
| 3 |
liveuser |
4166 |
}#if end
|
| 226 |
liveuser |
4167 |
|
| 3 |
liveuser |
4168 |
#函式說明:
|
|
|
4169 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
4170 |
#回傳結果:
|
|
|
4171 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4172 |
#$result["error"],錯誤訊息陣列.
|
|
|
4173 |
#$result["warning"],警告訊息鎮列.
|
|
|
4174 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
4175 |
#$result["function"],當前執行的函數名稱.
|
|
|
4176 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
4177 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
4178 |
#必填參數:
|
|
|
4179 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4180 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["input"];
|
|
|
4181 |
#$conf["keyWord"],字串,特定字串.
|
|
|
4182 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$conf["startKeyWord"];
|
|
|
4183 |
#可省略參數:
|
|
|
4184 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
4185 |
#$conf["recursive"]="true";
|
|
|
4186 |
#參考資料:
|
|
|
4187 |
#無.
|
|
|
4188 |
#備註:
|
|
|
4189 |
#無.
|
|
|
4190 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
4191 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
4192 |
|
| 3 |
liveuser |
4193 |
#如果執行失敗
|
|
|
4194 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
4195 |
|
| 3 |
liveuser |
4196 |
#設置執行失敗
|
|
|
4197 |
$result["status"]="false";
|
| 226 |
liveuser |
4198 |
|
| 3 |
liveuser |
4199 |
#設置執行錯誤訊息
|
|
|
4200 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
4201 |
|
| 3 |
liveuser |
4202 |
#回傳結果
|
|
|
4203 |
return $result;
|
| 226 |
liveuser |
4204 |
|
| 3 |
liveuser |
4205 |
}#if end
|
| 226 |
liveuser |
4206 |
|
| 3 |
liveuser |
4207 |
#函式說明:
|
|
|
4208 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
4209 |
#回傳結果:
|
|
|
4210 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4211 |
#$result["error"],錯誤訊息陣列.
|
|
|
4212 |
#$result["warning"],警告訊息鎮列.
|
|
|
4213 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
4214 |
#$result["function"],當前執行的函數名稱.
|
|
|
4215 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
4216 |
#$result["content"],處理好的的字串內容.
|
|
|
4217 |
#$result["argu"],使用的參數.
|
|
|
4218 |
#必填參數:
|
|
|
4219 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4220 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
|
|
|
4221 |
#$conf["keyWord"],字串,特定字串.
|
|
|
4222 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$conf["endKeyWord"];
|
|
|
4223 |
#可省略參數:
|
|
|
4224 |
#無.
|
|
|
4225 |
#參考資料:
|
|
|
4226 |
#無.
|
|
|
4227 |
#備註:
|
|
|
4228 |
#無.
|
|
|
4229 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
4230 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
| 226 |
liveuser |
4231 |
|
| 3 |
liveuser |
4232 |
#如果執行失敗
|
|
|
4233 |
if($delStrAfterKeyWord["status"]==="false"){
|
| 226 |
liveuser |
4234 |
|
| 3 |
liveuser |
4235 |
#設置執行失敗
|
|
|
4236 |
$result["status"]="false";
|
| 226 |
liveuser |
4237 |
|
| 3 |
liveuser |
4238 |
#設置執行錯誤訊息
|
|
|
4239 |
$result["error"]=$delStrAfterKeyWord;
|
| 226 |
liveuser |
4240 |
|
| 3 |
liveuser |
4241 |
#回傳結果
|
|
|
4242 |
return $result;
|
| 226 |
liveuser |
4243 |
|
| 3 |
liveuser |
4244 |
}#if end
|
| 226 |
liveuser |
4245 |
|
| 3 |
liveuser |
4246 |
#設置原始內容
|
|
|
4247 |
$result["oriStr"]=$conf["input"];
|
| 226 |
liveuser |
4248 |
|
| 3 |
liveuser |
4249 |
#設置處理後的內容
|
|
|
4250 |
$result["content"]=$delStrAfterKeyWord["content"];
|
| 226 |
liveuser |
4251 |
|
| 3 |
liveuser |
4252 |
#設置執行正常
|
|
|
4253 |
$result["status"]="true";
|
| 226 |
liveuser |
4254 |
|
| 3 |
liveuser |
4255 |
#回傳結果
|
|
|
4256 |
return $result;
|
| 226 |
liveuser |
4257 |
|
| 3 |
liveuser |
4258 |
}#function getContentBetweenKeyWord end
|
|
|
4259 |
|
|
|
4260 |
/*
|
|
|
4261 |
#函式說明:
|
|
|
4262 |
#將字串進行解析,變成多個參數.
|
|
|
4263 |
#回傳結果:
|
|
|
4264 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4265 |
#$result["function"],當前執行的函式內容.
|
|
|
4266 |
#$result["error"],錯誤訊息陣列.
|
|
|
4267 |
#$result["content"],參數陣列.
|
|
|
4268 |
#$result["count"],總共有幾個參數.
|
|
|
4269 |
#必填參數:
|
|
|
4270 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
4271 |
$conf["input"]="";
|
|
|
4272 |
#可省略參數:
|
|
|
4273 |
#無.
|
|
|
4274 |
#參考資料:
|
|
|
4275 |
#無.
|
|
|
4276 |
#備註:
|
|
|
4277 |
#無.
|
|
|
4278 |
*/
|
|
|
4279 |
public static function parse(&$conf){
|
| 226 |
liveuser |
4280 |
|
| 3 |
liveuser |
4281 |
#初始化要回傳的結果
|
|
|
4282 |
$result=array();
|
|
|
4283 |
|
|
|
4284 |
#取得當前執行的函數名稱
|
|
|
4285 |
$result["function"]=__FUNCTION__;
|
|
|
4286 |
|
|
|
4287 |
#如果沒有參數
|
|
|
4288 |
if(func_num_args()==0){
|
| 226 |
liveuser |
4289 |
|
| 3 |
liveuser |
4290 |
#設置執行失敗
|
|
|
4291 |
$result["status"]="false";
|
| 226 |
liveuser |
4292 |
|
| 3 |
liveuser |
4293 |
#設置執行錯誤訊息
|
|
|
4294 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
4295 |
|
| 3 |
liveuser |
4296 |
#回傳結果
|
|
|
4297 |
return $result;
|
| 226 |
liveuser |
4298 |
|
| 3 |
liveuser |
4299 |
}#if end
|
|
|
4300 |
|
|
|
4301 |
#取得參數
|
|
|
4302 |
$result["argu"]=$conf;
|
|
|
4303 |
|
|
|
4304 |
#如果 $conf 不為陣列
|
|
|
4305 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
4306 |
|
| 3 |
liveuser |
4307 |
#設置執行失敗
|
|
|
4308 |
$result["status"]="false";
|
| 226 |
liveuser |
4309 |
|
| 3 |
liveuser |
4310 |
#設置執行錯誤訊息
|
|
|
4311 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
4312 |
|
| 3 |
liveuser |
4313 |
#如果傳入的參數為 null
|
|
|
4314 |
if($conf===null){
|
| 226 |
liveuser |
4315 |
|
| 3 |
liveuser |
4316 |
#設置執行錯誤訊息
|
|
|
4317 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4318 |
|
| 3 |
liveuser |
4319 |
}#if end
|
|
|
4320 |
|
|
|
4321 |
#回傳結果
|
|
|
4322 |
return $result;
|
| 226 |
liveuser |
4323 |
|
| 3 |
liveuser |
4324 |
}#if end
|
| 226 |
liveuser |
4325 |
|
| 3 |
liveuser |
4326 |
#函式說明:
|
|
|
4327 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4328 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4329 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4330 |
#$result["function"],當前執行的函式名稱.
|
|
|
4331 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4332 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4333 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4334 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4335 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4336 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4337 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4338 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4339 |
#必填寫的參數:
|
|
|
4340 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4341 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4342 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4343 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
4344 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4345 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4346 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4347 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4348 |
#可以省略的參數:
|
|
|
4349 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
| 249 |
liveuser |
4350 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
| 3 |
liveuser |
4351 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4352 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4353 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4354 |
#$conf["canBeEmpty"]=array();
|
|
|
4355 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4356 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4357 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4358 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
4359 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4360 |
#$conf["skipableVariableType"]=array();
|
|
|
4361 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4362 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4363 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4364 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4365 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4366 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4367 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4368 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4369 |
#參考資料來源:
|
|
|
4370 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4371 |
#建議:
|
|
|
4372 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4373 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4374 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4375 |
|
| 3 |
liveuser |
4376 |
#如果檢查參數失敗
|
|
|
4377 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
4378 |
|
| 3 |
liveuser |
4379 |
#設置執行失敗
|
|
|
4380 |
$result["status"]="false";
|
| 226 |
liveuser |
4381 |
|
| 3 |
liveuser |
4382 |
#設置執行錯誤訊息
|
|
|
4383 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4384 |
|
| 3 |
liveuser |
4385 |
#回傳結果
|
|
|
4386 |
return $result;
|
| 226 |
liveuser |
4387 |
|
| 3 |
liveuser |
4388 |
}#if end
|
| 226 |
liveuser |
4389 |
|
| 3 |
liveuser |
4390 |
#如果檢查參數不通過
|
|
|
4391 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4392 |
|
| 3 |
liveuser |
4393 |
#設置執行失敗
|
|
|
4394 |
$result["status"]="false";
|
| 226 |
liveuser |
4395 |
|
| 3 |
liveuser |
4396 |
#設置執行錯誤訊息
|
|
|
4397 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4398 |
|
| 3 |
liveuser |
4399 |
#回傳結果
|
|
|
4400 |
return $result;
|
| 226 |
liveuser |
4401 |
|
| 3 |
liveuser |
4402 |
}#if end
|
| 226 |
liveuser |
4403 |
|
| 249 |
liveuser |
4404 |
#如果輸入為空
|
|
|
4405 |
if(empty($conf["input"])){
|
|
|
4406 |
|
|
|
4407 |
#設置沒有參數
|
|
|
4408 |
$result["content"]=array();
|
|
|
4409 |
|
|
|
4410 |
#設置參數數量
|
|
|
4411 |
$result["count"]=count($result["content"]);
|
|
|
4412 |
|
|
|
4413 |
#設置執行正常
|
|
|
4414 |
$result["status"]="true";
|
|
|
4415 |
|
|
|
4416 |
#回傳結果
|
|
|
4417 |
return $result;
|
|
|
4418 |
|
|
|
4419 |
}#if end
|
|
|
4420 |
|
| 3 |
liveuser |
4421 |
#預設存放 qbpwcf 可執行程式 parse 的位置
|
|
|
4422 |
$defaultQbpwcfUsrBinParse="/usr/bin/parse";
|
|
|
4423 |
|
|
|
4424 |
#預設存放 qbpwcf local 可執行程式 parse 的位置
|
| 21 |
liveuser |
4425 |
$defaultLocalQbpwcfUsrBinParse=pathinfo(__FILE__)["dirname"]."/../../bin/parse";
|
| 3 |
liveuser |
4426 |
|
|
|
4427 |
#預設存放 qbpwcf 可執行程式 parse 的位置
|
|
|
4428 |
$qbpwcfUsrBinParseArray=array($defaultLocalQbpwcfUsrBinParse,$defaultQbpwcfUsrBinParse);
|
|
|
4429 |
|
|
|
4430 |
#如果存在 include path
|
|
|
4431 |
if(get_include_path()!==false){
|
| 226 |
liveuser |
4432 |
|
| 3 |
liveuser |
4433 |
#函式說明:
|
|
|
4434 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
4435 |
#回傳結果:
|
|
|
4436 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4437 |
#$result["error"],錯誤訊息陣列
|
|
|
4438 |
#$result["function"],當前執行的函數名稱.
|
|
|
4439 |
#$result["argu"],使用的參數.
|
|
|
4440 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4441 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4442 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4443 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
4444 |
#必填參數:
|
|
|
4445 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4446 |
$conf["stringProcess::spiltString"]["stringIn"]=get_include_path();
|
|
|
4447 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
4448 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
|
|
|
4449 |
#可省略參數:
|
|
|
4450 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
4451 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
4452 |
#參考資料:
|
|
|
4453 |
#無.
|
|
|
4454 |
#備註:
|
|
|
4455 |
#無.
|
|
|
4456 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
4457 |
unset($conf["stringProcess::spiltString"]);
|
|
|
4458 |
|
|
|
4459 |
#如果執行失敗
|
|
|
4460 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
4461 |
|
| 3 |
liveuser |
4462 |
#設置執行失敗
|
|
|
4463 |
$result["status"]="false";
|
|
|
4464 |
|
|
|
4465 |
#設置執行錯誤
|
|
|
4466 |
$result["error"]=$spiltString;
|
|
|
4467 |
|
|
|
4468 |
#回傳結果
|
|
|
4469 |
return $result;
|
| 226 |
liveuser |
4470 |
|
| 3 |
liveuser |
4471 |
}#if end
|
| 226 |
liveuser |
4472 |
|
| 3 |
liveuser |
4473 |
#如果沒有符合的分割符號
|
|
|
4474 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
4475 |
|
| 3 |
liveuser |
4476 |
#設置執行失敗
|
|
|
4477 |
$result["status"]="false";
|
|
|
4478 |
|
|
|
4479 |
#設置執行錯誤
|
|
|
4480 |
$result["error"]=$spiltString;
|
|
|
4481 |
|
|
|
4482 |
#回傳結果
|
|
|
4483 |
return $result;
|
| 226 |
liveuser |
4484 |
|
| 3 |
liveuser |
4485 |
}#if end
|
| 226 |
liveuser |
4486 |
|
| 3 |
liveuser |
4487 |
#如果沒有切割出東西
|
|
|
4488 |
if($spiltString["dataCounts"]<1){
|
| 226 |
liveuser |
4489 |
|
| 3 |
liveuser |
4490 |
#設置執行失敗
|
|
|
4491 |
$result["status"]="false";
|
|
|
4492 |
|
|
|
4493 |
#設置執行錯誤
|
|
|
4494 |
$result["error"]=$spiltString;
|
|
|
4495 |
|
|
|
4496 |
#回傳結果
|
|
|
4497 |
return $result;
|
| 226 |
liveuser |
4498 |
|
| 3 |
liveuser |
4499 |
}#if end
|
| 226 |
liveuser |
4500 |
|
| 3 |
liveuser |
4501 |
#增加存放 qbpwcf 可執行程式 parse 的位置
|
|
|
4502 |
$qbpwcfUsrBinParseArray[]=$spiltString["dataArray"][0].$defaultQbpwcfUsrBinParse;
|
|
|
4503 |
|
|
|
4504 |
}#if end
|
| 226 |
liveuser |
4505 |
|
| 3 |
liveuser |
4506 |
#針對每個可能的 存放 qbpwcf 可執行程式的位置
|
|
|
4507 |
foreach($qbpwcfUsrBinParseArray as $index=>$qbpwcfUsrBinParse){
|
| 226 |
liveuser |
4508 |
|
| 3 |
liveuser |
4509 |
#如果檔案不存在
|
|
|
4510 |
if(!file_exists($qbpwcfUsrBinParse)){
|
|
|
4511 |
|
|
|
4512 |
#如果是最後一個檔案了
|
|
|
4513 |
if($index===count($qbpwcfUsrBinParseArray)-1){
|
| 226 |
liveuser |
4514 |
|
| 3 |
liveuser |
4515 |
#設置執行失敗
|
|
|
4516 |
$result["status"]="false";
|
|
|
4517 |
|
|
|
4518 |
#設置執行錯誤
|
|
|
4519 |
$result["error"]="檔案(".$qbpwcfUsrBinParse.")不存在";
|
|
|
4520 |
|
|
|
4521 |
#回傳結果
|
|
|
4522 |
return $result;
|
| 226 |
liveuser |
4523 |
|
| 3 |
liveuser |
4524 |
}#if end
|
| 226 |
liveuser |
4525 |
|
| 3 |
liveuser |
4526 |
}#if end
|
| 226 |
liveuser |
4527 |
|
| 3 |
liveuser |
4528 |
#反之檔案存在
|
|
|
4529 |
else{
|
| 226 |
liveuser |
4530 |
|
| 3 |
liveuser |
4531 |
#更新預設的 usr/bin/parse 位置
|
|
|
4532 |
$defaultQbpwcfUsrBinParse=$qbpwcfUsrBinParse;
|
| 226 |
liveuser |
4533 |
|
| 3 |
liveuser |
4534 |
#跳出 foreach
|
|
|
4535 |
break;
|
| 226 |
liveuser |
4536 |
|
| 3 |
liveuser |
4537 |
}#else end
|
| 226 |
liveuser |
4538 |
|
| 3 |
liveuser |
4539 |
}#foreach end
|
| 226 |
liveuser |
4540 |
|
| 3 |
liveuser |
4541 |
#建立暫存script檔案
|
|
|
4542 |
#函式說明:
|
| 226 |
liveuser |
4543 |
#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
|
| 3 |
liveuser |
4544 |
#回傳結果:
|
|
|
4545 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4546 |
#$result["error"],錯誤訊息.
|
|
|
4547 |
#$result["function"],當前執行的函數名稱.
|
|
|
4548 |
#$result["content"],暫存檔案的路徑與名稱.
|
|
|
4549 |
#$result["fileName"],暫存檔案的名稱.
|
|
|
4550 |
#$result["path"],暫存檔案的路徑.
|
|
|
4551 |
#必填參數:
|
|
|
4552 |
#無.
|
|
|
4553 |
#可省略參數:
|
|
|
4554 |
#無.
|
|
|
4555 |
#參考資料:
|
|
|
4556 |
#無.
|
|
|
4557 |
#備註:
|
|
|
4558 |
#無.
|
| 33 |
liveuser |
4559 |
$conf["fileAccess::createTempFile"]=array();
|
|
|
4560 |
$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
|
|
|
4561 |
unset($conf["fileAccess::createTempFile"]);
|
| 226 |
liveuser |
4562 |
|
| 3 |
liveuser |
4563 |
#如果沒有符合的分割符號
|
|
|
4564 |
if($createTempFile["status"]==="false"){
|
| 226 |
liveuser |
4565 |
|
| 3 |
liveuser |
4566 |
#設置執行失敗
|
|
|
4567 |
$result["status"]="false";
|
|
|
4568 |
|
|
|
4569 |
#設置執行錯誤
|
|
|
4570 |
$result["error"]=$createTempFile;
|
|
|
4571 |
|
|
|
4572 |
#回傳結果
|
|
|
4573 |
return $result;
|
| 226 |
liveuser |
4574 |
|
| 3 |
liveuser |
4575 |
}#if end
|
| 226 |
liveuser |
4576 |
|
| 3 |
liveuser |
4577 |
#取得暫存檔案的路徑與名稱
|
|
|
4578 |
$scriptFile2test=$createTempFile["content"];
|
| 226 |
liveuser |
4579 |
|
| 3 |
liveuser |
4580 |
#將要檢查的shell script寫入
|
|
|
4581 |
#函式說明:
|
|
|
4582 |
#將字串寫入到檔案
|
|
|
4583 |
#回傳結果:
|
|
|
4584 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
4585 |
#$result["error"],錯誤訊息陣列.
|
|
|
4586 |
#$result["function"],當前執行的函數名稱.
|
|
|
4587 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
4588 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
4589 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
4590 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
4591 |
#$result["argu"],使用的參數.
|
|
|
4592 |
#必填參數:
|
|
|
4593 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4594 |
$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
|
|
|
4595 |
#可省略參數:
|
|
|
4596 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
4597 |
$conf["fileAccess::writeTextIntoFile"]["fileName"]=$scriptFile2test;
|
|
|
4598 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
4599 |
$conf["fileAccess::writeTextIntoFile"]["inputString"]="#!/bin/bash".PHP_EOL.$conf["input"].PHP_EOL;
|
|
|
4600 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
4601 |
#$conf["writeMethod"]="a";
|
|
|
4602 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
4603 |
#$conf["checkRepeat"]="";
|
|
|
4604 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
4605 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
4606 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
4607 |
#$conf["repeatNameRule"]="";
|
|
|
4608 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
4609 |
$conf["fileAccess::writeTextIntoFile"]["web"]="false";
|
|
|
4610 |
#參考資料:
|
|
|
4611 |
#無.
|
|
|
4612 |
#備註:
|
|
|
4613 |
#無.
|
|
|
4614 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
|
|
|
4615 |
unset($conf["fileAccess::writeTextIntoFile"]);
|
| 226 |
liveuser |
4616 |
|
| 3 |
liveuser |
4617 |
#如果執行失敗
|
|
|
4618 |
if($writeTextIntoFile["status"]==="false"){
|
| 226 |
liveuser |
4619 |
|
| 3 |
liveuser |
4620 |
#設置執行失敗
|
|
|
4621 |
$result["status"]="false";
|
|
|
4622 |
|
|
|
4623 |
#設置執行錯誤
|
|
|
4624 |
$result["error"]=$writeTextIntoFile;
|
|
|
4625 |
|
|
|
4626 |
#回傳結果
|
|
|
4627 |
return $result;
|
| 226 |
liveuser |
4628 |
|
| 3 |
liveuser |
4629 |
}#if end
|
| 226 |
liveuser |
4630 |
|
| 3 |
liveuser |
4631 |
#檢查有無語法錯誤
|
|
|
4632 |
$cmd="bash -n ".$scriptFile2test;
|
| 226 |
liveuser |
4633 |
|
| 3 |
liveuser |
4634 |
#函式說明:
|
|
|
4635 |
#透過proc來多執行序運作.
|
|
|
4636 |
#回傳結果:
|
|
|
4637 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4638 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4639 |
#$result["function"],當前執行的函式名稱.
|
|
|
4640 |
#$result["argu"],使用的參數.
|
|
|
4641 |
#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
|
|
|
4642 |
#必填參數:
|
|
|
4643 |
#$conf["cmds"],字串陣列,每個元素代表要執行的指令與參數.
|
|
|
4644 |
$conf["threads::proc"]["cmds"]=array($cmd);
|
|
|
4645 |
#可省略參數:
|
|
|
4646 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
4647 |
#$conf["threads::proc"]["wait"]="false";
|
|
|
4648 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
4649 |
#$conf["workingDir"]=array("path");
|
|
|
4650 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
4651 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
4652 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
4653 |
#$conf["executeBy"]=array("bash");
|
|
|
4654 |
#參考資料:
|
|
|
4655 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
4656 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
4657 |
#備註:
|
|
|
4658 |
#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
4659 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
4660 |
unset($conf["threads::proc"]);
|
| 226 |
liveuser |
4661 |
|
| 3 |
liveuser |
4662 |
#如果執行失敗
|
|
|
4663 |
if($proc["status"]==="false"){
|
| 226 |
liveuser |
4664 |
|
| 3 |
liveuser |
4665 |
#設置執行失敗
|
|
|
4666 |
$result["status"]="false";
|
|
|
4667 |
|
|
|
4668 |
#設置錯誤訊息
|
|
|
4669 |
$result["error"][]="檢查bash語法出錯";
|
|
|
4670 |
|
|
|
4671 |
#設置執行錯誤
|
|
|
4672 |
$result["error"][]=$proc;
|
|
|
4673 |
|
|
|
4674 |
#回傳結果
|
|
|
4675 |
return $result;
|
| 226 |
liveuser |
4676 |
|
| 3 |
liveuser |
4677 |
}#if end
|
| 226 |
liveuser |
4678 |
|
| 3 |
liveuser |
4679 |
#如果執行失敗
|
|
|
4680 |
if($proc["content"][0]["statusCode"]!==0){
|
| 226 |
liveuser |
4681 |
|
| 3 |
liveuser |
4682 |
#如果錯誤訊息為語法錯誤
|
|
|
4683 |
if(strpos($proc["content"][0]["error"],"syntax error")!==false){
|
| 226 |
liveuser |
4684 |
|
| 3 |
liveuser |
4685 |
#遞迴呼叫
|
|
|
4686 |
#函式說明:
|
|
|
4687 |
#將字串進行解析,變成多個參數.
|
|
|
4688 |
#回傳結果:
|
|
|
4689 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4690 |
#$result["function"],當前執行的函式內容.
|
|
|
4691 |
#$result["error"],錯誤訊息陣列.
|
|
|
4692 |
#$result["content"],參數陣列.
|
|
|
4693 |
#$result["count"],總共有幾個參數.
|
|
|
4694 |
#必填參數:
|
|
|
4695 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
4696 |
$conf["self::parse"]["input"]=\escapeshellarg($conf["input"]);
|
|
|
4697 |
#可省略參數:
|
|
|
4698 |
#無.
|
|
|
4699 |
#參考資料:
|
|
|
4700 |
#無.
|
|
|
4701 |
#備註:
|
|
|
4702 |
#無.
|
|
|
4703 |
$parse=self::parse($conf["self::parse"]);
|
|
|
4704 |
unset($conf["self::parse"]);
|
| 226 |
liveuser |
4705 |
|
| 3 |
liveuser |
4706 |
#回傳結果
|
|
|
4707 |
return $parse;
|
| 226 |
liveuser |
4708 |
|
| 3 |
liveuser |
4709 |
}#if end
|
| 226 |
liveuser |
4710 |
|
| 3 |
liveuser |
4711 |
#取得錯誤訊息
|
| 226 |
liveuser |
4712 |
|
| 3 |
liveuser |
4713 |
#設置執行失敗
|
|
|
4714 |
$result["status"]="false";
|
|
|
4715 |
|
|
|
4716 |
#設置錯誤訊息
|
|
|
4717 |
$result["error"][]="Bash syntax error or Permission denied";
|
|
|
4718 |
|
|
|
4719 |
#設置執行錯誤
|
|
|
4720 |
$result["error"][]=$proc;
|
|
|
4721 |
|
|
|
4722 |
#回傳結果
|
|
|
4723 |
return $result;
|
| 226 |
liveuser |
4724 |
|
| 3 |
liveuser |
4725 |
}#if end
|
| 226 |
liveuser |
4726 |
|
| 3 |
liveuser |
4727 |
#移除暫存檔案
|
|
|
4728 |
unlink($scriptFile2test);
|
| 226 |
liveuser |
4729 |
|
| 3 |
liveuser |
4730 |
#預設要運行的指令
|
| 249 |
liveuser |
4731 |
#$cmd=$defaultQbpwcfUsrBinParse.' '.$conf["input"];
|
|
|
4732 |
|
|
|
4733 |
#函式說明:
|
|
|
4734 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
4735 |
#回傳結果:
|
|
|
4736 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4737 |
#$result["error"],錯誤訊息陣列.
|
|
|
4738 |
#$result["function"],當前執行的函數名稱.
|
|
|
4739 |
#$result["argu"],使用的參數.
|
|
|
4740 |
#$result["cmd"],執行的指令內容.
|
|
|
4741 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
4742 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
4743 |
#$result["content"],為執行完後的輸出字串.
|
|
|
4744 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
4745 |
#$result["running"],是否還在執行.
|
|
|
4746 |
#$result["pid"],pid.
|
|
|
4747 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
4748 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
4749 |
#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
|
|
4750 |
#必填參數:
|
|
|
4751 |
#$conf["command"],字串,要執行的指令.
|
|
|
4752 |
$conf["external::callShell"]["command"]=$defaultQbpwcfUsrBinParse;
|
|
|
4753 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
4754 |
$conf["external::callShell"]["fileArgu"]=__FILE__;
|
|
|
4755 |
#可省略參數:
|
|
|
4756 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
4757 |
$conf["external::callShell"]["argu"]=array($conf["input"]);
|
|
|
4758 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
4759 |
#$conf["arguIsAddr"]=array();
|
|
|
4760 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
4761 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
4762 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
4763 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
4764 |
#$conf["enablePrintDescription"]="true";
|
|
|
4765 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
4766 |
#$conf["printDescription"]="";
|
|
|
4767 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
4768 |
#$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
4769 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
4770 |
#$conf["thereIsShellVar"]=array();
|
|
|
4771 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
4772 |
#$conf["username"]="";
|
|
|
4773 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
4774 |
#$conf["password"]="";
|
|
|
4775 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
4776 |
#$conf["useScript"]="";
|
|
|
4777 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
4778 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
4779 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
4780 |
#$conf["inBackGround"]="";
|
|
|
4781 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
4782 |
#$conf["getErr"]="false";
|
|
|
4783 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
4784 |
#$conf["doNotRun"]="false";
|
|
|
4785 |
#參考資料:
|
|
|
4786 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
4787 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
4788 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
4789 |
#備註:
|
|
|
4790 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
4791 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
4792 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
4793 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
4794 |
|
| 249 |
liveuser |
4795 |
#如果執行異常
|
|
|
4796 |
if($callShell["status"]==="false"){
|
|
|
4797 |
|
|
|
4798 |
#設置執行失敗
|
|
|
4799 |
$result["status"]="false";
|
| 226 |
liveuser |
4800 |
|
| 249 |
liveuser |
4801 |
#設置執行錯誤訊息
|
|
|
4802 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
4803 |
|
| 249 |
liveuser |
4804 |
#回傳結果
|
|
|
4805 |
return $result;
|
|
|
4806 |
|
|
|
4807 |
}#if end
|
| 226 |
liveuser |
4808 |
|
| 249 |
liveuser |
4809 |
#設置執行正常
|
|
|
4810 |
$result["status"]="true";
|
| 226 |
liveuser |
4811 |
|
| 249 |
liveuser |
4812 |
#如果輸出不是 json
|
|
|
4813 |
if(json_validate($callShell["content"])===false){
|
| 226 |
liveuser |
4814 |
|
| 249 |
liveuser |
4815 |
#設置執行失敗
|
|
|
4816 |
$result["status"]="false";
|
| 226 |
liveuser |
4817 |
|
| 249 |
liveuser |
4818 |
#設置執行錯誤訊息
|
|
|
4819 |
$result["error"][]="not json output";
|
| 226 |
liveuser |
4820 |
|
| 249 |
liveuser |
4821 |
#設置執行錯誤訊息
|
|
|
4822 |
$result["error"][]=$callShell["content"];
|
| 226 |
liveuser |
4823 |
|
| 249 |
liveuser |
4824 |
#回傳結果
|
|
|
4825 |
return $result;
|
| 226 |
liveuser |
4826 |
|
| 249 |
liveuser |
4827 |
}#if end
|
| 226 |
liveuser |
4828 |
|
| 249 |
liveuser |
4829 |
#解析json,並轉成array
|
|
|
4830 |
$output=(array)json_decode($callShell["content"]);
|
| 226 |
liveuser |
4831 |
|
| 249 |
liveuser |
4832 |
#移除被執行的php檔案名稱
|
|
|
4833 |
unset($output[0]);
|
| 226 |
liveuser |
4834 |
|
| 249 |
liveuser |
4835 |
#初始化參數陣列
|
|
|
4836 |
$params=array();
|
| 226 |
liveuser |
4837 |
|
| 249 |
liveuser |
4838 |
#針對每個參數
|
|
|
4839 |
foreach($output as $param){
|
| 226 |
liveuser |
4840 |
|
| 249 |
liveuser |
4841 |
#取得參數
|
|
|
4842 |
$params[]=$param;
|
| 226 |
liveuser |
4843 |
|
| 249 |
liveuser |
4844 |
}#foreach end
|
| 226 |
liveuser |
4845 |
|
| 249 |
liveuser |
4846 |
#取得參數陣列
|
|
|
4847 |
$result["content"]=$params;
|
| 226 |
liveuser |
4848 |
|
| 249 |
liveuser |
4849 |
#取得參數數目
|
|
|
4850 |
$result["count"]=count($params);
|
| 226 |
liveuser |
4851 |
|
| 249 |
liveuser |
4852 |
#回傳結果
|
|
|
4853 |
return $result;
|
| 226 |
liveuser |
4854 |
|
| 3 |
liveuser |
4855 |
}#function parse end
|
| 226 |
liveuser |
4856 |
|
| 3 |
liveuser |
4857 |
/*
|
|
|
4858 |
#函式說明:
|
|
|
4859 |
#清除字串的「"」或「'」符號.
|
|
|
4860 |
#回傳結果:
|
|
|
4861 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4862 |
#$result["function"],當前執行的函式內容.
|
|
|
4863 |
#$result["error"],錯誤訊息陣列.
|
|
|
4864 |
#$result["content"],剔除「"」或「'」符號後的字串.
|
|
|
4865 |
#必填參數:
|
|
|
4866 |
#$conf["str"],字串,要處理的字串.
|
|
|
4867 |
$conf["str"]="";
|
|
|
4868 |
#可省略參數:
|
|
|
4869 |
#無.
|
|
|
4870 |
#參考資料:
|
|
|
4871 |
#無.
|
|
|
4872 |
#備註:
|
|
|
4873 |
#無.
|
|
|
4874 |
*/
|
|
|
4875 |
public static function clearStrSymbol(&$conf){
|
| 226 |
liveuser |
4876 |
|
| 3 |
liveuser |
4877 |
#初始化要回傳的結果
|
|
|
4878 |
$result=array();
|
|
|
4879 |
|
|
|
4880 |
#取得當前執行的函數名稱
|
|
|
4881 |
$result["function"]=__FUNCTION__;
|
|
|
4882 |
|
|
|
4883 |
#如果沒有參數
|
|
|
4884 |
if(func_num_args()==0){
|
| 226 |
liveuser |
4885 |
|
| 3 |
liveuser |
4886 |
#設置執行失敗
|
|
|
4887 |
$result["status"]="false";
|
| 226 |
liveuser |
4888 |
|
| 3 |
liveuser |
4889 |
#設置執行錯誤訊息
|
|
|
4890 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
4891 |
|
| 3 |
liveuser |
4892 |
#回傳結果
|
|
|
4893 |
return $result;
|
| 226 |
liveuser |
4894 |
|
| 3 |
liveuser |
4895 |
}#if end
|
|
|
4896 |
|
|
|
4897 |
#取得參數
|
|
|
4898 |
$result["argu"]=$conf;
|
|
|
4899 |
|
|
|
4900 |
#如果 $conf 不為陣列
|
|
|
4901 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
4902 |
|
| 3 |
liveuser |
4903 |
#設置執行失敗
|
|
|
4904 |
$result["status"]="false";
|
| 226 |
liveuser |
4905 |
|
| 3 |
liveuser |
4906 |
#設置執行錯誤訊息
|
|
|
4907 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
4908 |
|
| 3 |
liveuser |
4909 |
#如果傳入的參數為 null
|
|
|
4910 |
if($conf===null){
|
| 226 |
liveuser |
4911 |
|
| 3 |
liveuser |
4912 |
#設置執行錯誤訊息
|
|
|
4913 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4914 |
|
| 3 |
liveuser |
4915 |
}#if end
|
|
|
4916 |
|
|
|
4917 |
#回傳結果
|
|
|
4918 |
return $result;
|
| 226 |
liveuser |
4919 |
|
| 3 |
liveuser |
4920 |
}#if end
|
| 226 |
liveuser |
4921 |
|
| 3 |
liveuser |
4922 |
#函式說明:
|
|
|
4923 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4924 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4925 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4926 |
#$result["function"],當前執行的函式名稱.
|
|
|
4927 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4928 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4929 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4930 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4931 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4932 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4933 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4934 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4935 |
#必填寫的參數:
|
|
|
4936 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4937 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4938 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4939 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("str");
|
|
|
4940 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4941 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4942 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4943 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4944 |
#可以省略的參數:
|
|
|
4945 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4946 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
4947 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4948 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4949 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4950 |
#$conf["canBeEmpty"]=array();
|
|
|
4951 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4952 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4953 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4954 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
4955 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4956 |
#$conf["skipableVariableType"]=array();
|
|
|
4957 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4958 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4959 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4960 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4961 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4962 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4963 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4964 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4965 |
#參考資料來源:
|
|
|
4966 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4967 |
#建議:
|
|
|
4968 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4969 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4970 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4971 |
|
| 3 |
liveuser |
4972 |
#如果檢查參數失敗
|
|
|
4973 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
4974 |
|
| 3 |
liveuser |
4975 |
#設置執行失敗
|
|
|
4976 |
$result["status"]="false";
|
| 226 |
liveuser |
4977 |
|
| 3 |
liveuser |
4978 |
#設置執行錯誤訊息
|
|
|
4979 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4980 |
|
| 3 |
liveuser |
4981 |
#回傳結果
|
|
|
4982 |
return $result;
|
| 226 |
liveuser |
4983 |
|
| 3 |
liveuser |
4984 |
}#if end
|
| 226 |
liveuser |
4985 |
|
| 3 |
liveuser |
4986 |
#如果檢查參數不通過
|
|
|
4987 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4988 |
|
| 3 |
liveuser |
4989 |
#設置執行失敗
|
|
|
4990 |
$result["status"]="false";
|
| 226 |
liveuser |
4991 |
|
| 3 |
liveuser |
4992 |
#設置執行錯誤訊息
|
|
|
4993 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4994 |
|
| 3 |
liveuser |
4995 |
#回傳結果
|
|
|
4996 |
return $result;
|
| 226 |
liveuser |
4997 |
|
| 3 |
liveuser |
4998 |
}#if end
|
| 226 |
liveuser |
4999 |
|
| 3 |
liveuser |
5000 |
#取得參數
|
|
|
5001 |
$str=$conf["str"];
|
| 226 |
liveuser |
5002 |
|
| 3 |
liveuser |
5003 |
#檢查是否有「"」在開頭
|
| 226 |
liveuser |
5004 |
$strHeadSymbol1=strpos($str,"\"");
|
|
|
5005 |
|
| 3 |
liveuser |
5006 |
#檢查是否有「'」在開頭
|
|
|
5007 |
$strHeadSymbol2=strpos($str,"'");
|
| 226 |
liveuser |
5008 |
|
| 3 |
liveuser |
5009 |
#分割輸入的字串為一個個字的陣列
|
| 226 |
liveuser |
5010 |
$splitedFileName=str_split($str);
|
|
|
5011 |
|
| 3 |
liveuser |
5012 |
#取得輸入參數的長度
|
|
|
5013 |
$fileNameStrlen=strlen($str);
|
|
|
5014 |
|
|
|
5015 |
#如果檔案名稱被「"」或「'」包住
|
|
|
5016 |
if
|
|
|
5017 |
(
|
| 226 |
liveuser |
5018 |
$strHeadSymbol1===0 && $splitedFileName[$fileNameStrlen-1]==="\""
|
| 3 |
liveuser |
5019 |
||
|
| 226 |
liveuser |
5020 |
$strHeadSymbol2===0 && $splitedFileName[$fileNameStrlen-1]==="'"
|
| 3 |
liveuser |
5021 |
){
|
| 226 |
liveuser |
5022 |
|
| 3 |
liveuser |
5023 |
#初始化儲存處理好的字串
|
|
|
5024 |
$fixedStr="";
|
| 226 |
liveuser |
5025 |
|
| 3 |
liveuser |
5026 |
#將字串的「"」包住的內容
|
|
|
5027 |
for($i=1;$i<$fileNameStrlen-1;$i++){
|
| 226 |
liveuser |
5028 |
|
| 3 |
liveuser |
5029 |
#取出
|
|
|
5030 |
$fixedStr=$fixedStr.$splitedFileName[$i];
|
| 226 |
liveuser |
5031 |
|
| 3 |
liveuser |
5032 |
}#for end
|
| 226 |
liveuser |
5033 |
|
| 3 |
liveuser |
5034 |
#儲存處理好的字串
|
|
|
5035 |
$result["content"]=$fixedStr;
|
| 226 |
liveuser |
5036 |
|
| 3 |
liveuser |
5037 |
}#if end
|
| 226 |
liveuser |
5038 |
|
| 3 |
liveuser |
5039 |
#儲存原先的字串
|
|
|
5040 |
$result["content"]=$str;
|
| 226 |
liveuser |
5041 |
|
| 3 |
liveuser |
5042 |
#設置執行正常
|
|
|
5043 |
$result["status"]="true";
|
| 226 |
liveuser |
5044 |
|
| 3 |
liveuser |
5045 |
#回傳結果
|
|
|
5046 |
return $result;
|
| 226 |
liveuser |
5047 |
|
| 3 |
liveuser |
5048 |
}#function clearStrSymbol end
|
| 226 |
liveuser |
5049 |
|
| 3 |
liveuser |
5050 |
/*
|
|
|
5051 |
#函式說明:
|
|
|
5052 |
#將字串中的每個字變成hex的字串陣列
|
|
|
5053 |
#回傳結果:
|
|
|
5054 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5055 |
#$result["function"],當前執行的函式內容.
|
|
|
5056 |
#$result["error"],錯誤訊息陣列.
|
|
|
5057 |
#$result["content"],hex的字串陣列.
|
|
|
5058 |
#必填參數:
|
|
|
5059 |
#$conf["input"],字串,要轉換成bytes陣列的字串.
|
|
|
5060 |
$conf["input"]="";
|
|
|
5061 |
#可省略參數:
|
|
|
5062 |
#無.
|
|
|
5063 |
#參考資料:
|
|
|
5064 |
#無.
|
|
|
5065 |
#備註:
|
|
|
5066 |
#無.
|
| 226 |
liveuser |
5067 |
*/
|
| 3 |
liveuser |
5068 |
public static function str2bytesArray(&$conf){
|
| 226 |
liveuser |
5069 |
|
| 3 |
liveuser |
5070 |
#初始化要回傳的結果
|
|
|
5071 |
$result=array();
|
|
|
5072 |
|
|
|
5073 |
#取得當前執行的函數名稱
|
|
|
5074 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5075 |
|
| 3 |
liveuser |
5076 |
#初始化儲存bytes陣列
|
|
|
5077 |
$result["content"]=array();
|
|
|
5078 |
|
|
|
5079 |
#如果沒有參數
|
|
|
5080 |
if(func_num_args()==0){
|
| 226 |
liveuser |
5081 |
|
| 3 |
liveuser |
5082 |
#設置執行失敗
|
|
|
5083 |
$result["status"]="false";
|
| 226 |
liveuser |
5084 |
|
| 3 |
liveuser |
5085 |
#設置執行錯誤訊息
|
|
|
5086 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
5087 |
|
| 3 |
liveuser |
5088 |
#回傳結果
|
|
|
5089 |
return $result;
|
| 226 |
liveuser |
5090 |
|
| 3 |
liveuser |
5091 |
}#if end
|
|
|
5092 |
|
|
|
5093 |
#取得參數
|
|
|
5094 |
$result["argu"]=$conf;
|
|
|
5095 |
|
|
|
5096 |
#如果 $conf 不為陣列
|
|
|
5097 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
5098 |
|
| 3 |
liveuser |
5099 |
#設置執行失敗
|
|
|
5100 |
$result["status"]="false";
|
| 226 |
liveuser |
5101 |
|
| 3 |
liveuser |
5102 |
#設置執行錯誤訊息
|
|
|
5103 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
5104 |
|
| 3 |
liveuser |
5105 |
#如果傳入的參數為 null
|
|
|
5106 |
if($conf===null){
|
| 226 |
liveuser |
5107 |
|
| 3 |
liveuser |
5108 |
#設置執行錯誤訊息
|
|
|
5109 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
5110 |
|
| 3 |
liveuser |
5111 |
}#if end
|
|
|
5112 |
|
|
|
5113 |
#回傳結果
|
|
|
5114 |
return $result;
|
| 226 |
liveuser |
5115 |
|
| 3 |
liveuser |
5116 |
}#if end
|
| 226 |
liveuser |
5117 |
|
| 3 |
liveuser |
5118 |
#函式說明:
|
|
|
5119 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5120 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5121 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5122 |
#$result["function"],當前執行的函式名稱.
|
|
|
5123 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5124 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5125 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5126 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5127 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5128 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5129 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5130 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5131 |
#必填寫的參數:
|
|
|
5132 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5133 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5134 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5135 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
5136 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
5137 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5138 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5139 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5140 |
#可以省略的參數:
|
|
|
5141 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5142 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
5143 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5144 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5145 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5146 |
#$conf["canBeEmpty"]=array();
|
|
|
5147 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5148 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5149 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5150 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
5151 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
5152 |
#$conf["skipableVariableType"]=array();
|
|
|
5153 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5154 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5155 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5156 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5157 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5158 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5159 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5160 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5161 |
#參考資料來源:
|
|
|
5162 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5163 |
#建議:
|
|
|
5164 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
5165 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5166 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5167 |
|
| 3 |
liveuser |
5168 |
#如果檢查參數失敗
|
|
|
5169 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5170 |
|
| 3 |
liveuser |
5171 |
#設置執行失敗
|
|
|
5172 |
$result["status"]="false";
|
| 226 |
liveuser |
5173 |
|
| 3 |
liveuser |
5174 |
#設置執行錯誤訊息
|
|
|
5175 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5176 |
|
| 3 |
liveuser |
5177 |
#回傳結果
|
|
|
5178 |
return $result;
|
| 226 |
liveuser |
5179 |
|
| 3 |
liveuser |
5180 |
}#if end
|
| 226 |
liveuser |
5181 |
|
| 3 |
liveuser |
5182 |
#如果檢查參數不通過
|
|
|
5183 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
5184 |
|
| 3 |
liveuser |
5185 |
#設置執行失敗
|
|
|
5186 |
$result["status"]="false";
|
| 226 |
liveuser |
5187 |
|
| 3 |
liveuser |
5188 |
#設置執行錯誤訊息
|
|
|
5189 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5190 |
|
| 3 |
liveuser |
5191 |
#回傳結果
|
|
|
5192 |
return $result;
|
| 226 |
liveuser |
5193 |
|
| 3 |
liveuser |
5194 |
}#if end
|
| 226 |
liveuser |
5195 |
|
| 3 |
liveuser |
5196 |
#當字串還有內容
|
|
|
5197 |
while(strlen($conf["input"])>0)
|
|
|
5198 |
{
|
|
|
5199 |
#取得一個字串
|
| 226 |
liveuser |
5200 |
$char=substr($conf["input"],0,1);
|
|
|
5201 |
|
| 3 |
liveuser |
5202 |
#儲存16進位的bytes數字
|
|
|
5203 |
$result["content"][]=strtoupper(sprintf("%02s",(base_convert(ord($char),10,16))));
|
| 226 |
liveuser |
5204 |
|
| 3 |
liveuser |
5205 |
#取得剩下的字串
|
|
|
5206 |
$conf["input"]=substr($conf["input"],1);
|
| 226 |
liveuser |
5207 |
|
| 3 |
liveuser |
5208 |
}#while end
|
| 226 |
liveuser |
5209 |
|
| 3 |
liveuser |
5210 |
#設置執行正常
|
|
|
5211 |
$result["status"]="true";
|
| 226 |
liveuser |
5212 |
|
| 3 |
liveuser |
5213 |
#回傳
|
|
|
5214 |
return $result;
|
| 226 |
liveuser |
5215 |
|
| 3 |
liveuser |
5216 |
}#funcrion str2bytesArray end
|
| 226 |
liveuser |
5217 |
|
| 3 |
liveuser |
5218 |
/*
|
|
|
5219 |
#函式說明:
|
|
|
5220 |
#將字串中的每個字變成hex的字串
|
|
|
5221 |
#回傳結果:
|
|
|
5222 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5223 |
#$result["function"],當前執行的函式內容.
|
|
|
5224 |
#$result["error"],錯誤訊息陣列.
|
|
|
5225 |
#$result["content"],hex字串.
|
|
|
5226 |
#必填參數:
|
|
|
5227 |
#$conf["input"],字串,要轉換成hex字串的字串.
|
|
|
5228 |
$conf["input"]="";
|
|
|
5229 |
#可省略參數:
|
|
|
5230 |
#無.
|
|
|
5231 |
#參考資料:
|
|
|
5232 |
#無.
|
|
|
5233 |
#備註:
|
|
|
5234 |
#無.
|
| 226 |
liveuser |
5235 |
*/
|
| 3 |
liveuser |
5236 |
public static function str2hexStr(&$conf){
|
| 226 |
liveuser |
5237 |
|
| 3 |
liveuser |
5238 |
#初始化要回傳的結果
|
|
|
5239 |
$result=array();
|
|
|
5240 |
|
|
|
5241 |
#取得當前執行的函數名稱
|
|
|
5242 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5243 |
|
| 3 |
liveuser |
5244 |
#初始化儲存bytes陣列
|
|
|
5245 |
$result["content"]=array();
|
|
|
5246 |
|
|
|
5247 |
#如果沒有參數
|
|
|
5248 |
if(func_num_args()==0){
|
| 226 |
liveuser |
5249 |
|
| 3 |
liveuser |
5250 |
#設置執行失敗
|
|
|
5251 |
$result["status"]="false";
|
| 226 |
liveuser |
5252 |
|
| 3 |
liveuser |
5253 |
#設置執行錯誤訊息
|
|
|
5254 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
5255 |
|
| 3 |
liveuser |
5256 |
#回傳結果
|
|
|
5257 |
return $result;
|
| 226 |
liveuser |
5258 |
|
| 3 |
liveuser |
5259 |
}#if end
|
|
|
5260 |
|
|
|
5261 |
#取得參數
|
|
|
5262 |
$result["argu"]=$conf;
|
|
|
5263 |
|
|
|
5264 |
#如果 $conf 不為陣列
|
|
|
5265 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
5266 |
|
| 3 |
liveuser |
5267 |
#設置執行失敗
|
|
|
5268 |
$result["status"]="false";
|
| 226 |
liveuser |
5269 |
|
| 3 |
liveuser |
5270 |
#設置執行錯誤訊息
|
|
|
5271 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
5272 |
|
| 3 |
liveuser |
5273 |
#如果傳入的參數為 null
|
|
|
5274 |
if($conf===null){
|
| 226 |
liveuser |
5275 |
|
| 3 |
liveuser |
5276 |
#設置執行錯誤訊息
|
|
|
5277 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
5278 |
|
| 3 |
liveuser |
5279 |
}#if end
|
|
|
5280 |
|
|
|
5281 |
#回傳結果
|
|
|
5282 |
return $result;
|
| 226 |
liveuser |
5283 |
|
| 3 |
liveuser |
5284 |
}#if end
|
| 226 |
liveuser |
5285 |
|
| 3 |
liveuser |
5286 |
#函式說明:
|
|
|
5287 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5288 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5289 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5290 |
#$result["function"],當前執行的函式名稱.
|
|
|
5291 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5292 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5293 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5294 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5295 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5296 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5297 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5298 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5299 |
#必填寫的參數:
|
|
|
5300 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5301 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5302 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5303 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
5304 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
5305 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5306 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5307 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5308 |
#可以省略的參數:
|
|
|
5309 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5310 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
5311 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5312 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5313 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5314 |
#$conf["canBeEmpty"]=array();
|
|
|
5315 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5316 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5317 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5318 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
5319 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
5320 |
#$conf["skipableVariableType"]=array();
|
|
|
5321 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5322 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5323 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5324 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5325 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5326 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5327 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5328 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5329 |
#參考資料來源:
|
|
|
5330 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5331 |
#建議:
|
|
|
5332 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
5333 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5334 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5335 |
|
| 3 |
liveuser |
5336 |
#如果檢查參數失敗
|
|
|
5337 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5338 |
|
| 3 |
liveuser |
5339 |
#設置執行失敗
|
|
|
5340 |
$result["status"]="false";
|
| 226 |
liveuser |
5341 |
|
| 3 |
liveuser |
5342 |
#設置執行錯誤訊息
|
|
|
5343 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5344 |
|
| 3 |
liveuser |
5345 |
#回傳結果
|
|
|
5346 |
return $result;
|
| 226 |
liveuser |
5347 |
|
| 3 |
liveuser |
5348 |
}#if end
|
| 226 |
liveuser |
5349 |
|
| 3 |
liveuser |
5350 |
#如果檢查參數不通過
|
|
|
5351 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
5352 |
|
| 3 |
liveuser |
5353 |
#設置執行失敗
|
|
|
5354 |
$result["status"]="false";
|
| 226 |
liveuser |
5355 |
|
| 3 |
liveuser |
5356 |
#設置執行錯誤訊息
|
|
|
5357 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5358 |
|
| 3 |
liveuser |
5359 |
#回傳結果
|
|
|
5360 |
return $result;
|
| 226 |
liveuser |
5361 |
|
| 3 |
liveuser |
5362 |
}#if end
|
| 226 |
liveuser |
5363 |
|
| 3 |
liveuser |
5364 |
#透過 stringProcess::str2bytesArray 取得 hex字串陣列
|
|
|
5365 |
$conf["stringProcess::str2bytesArray"]["input"]=$conf;
|
|
|
5366 |
$str2bytesArray=stringProcess::str2bytesArray($conf["stringProcess::str2bytesArray"]);
|
|
|
5367 |
unset($conf["stringProcess::str2bytesArray"]);
|
| 226 |
liveuser |
5368 |
|
| 3 |
liveuser |
5369 |
#如果執行失敗
|
|
|
5370 |
if($str2bytesArray["status"]==="false"){
|
| 226 |
liveuser |
5371 |
|
| 3 |
liveuser |
5372 |
#設置執行不正常
|
|
|
5373 |
$result["status"]="false";
|
| 226 |
liveuser |
5374 |
|
| 3 |
liveuser |
5375 |
#設置錯誤訊息
|
|
|
5376 |
$result["error"]=$str2bytesArray;
|
| 226 |
liveuser |
5377 |
|
| 3 |
liveuser |
5378 |
#回傳結果
|
|
|
5379 |
return $resutl;
|
| 226 |
liveuser |
5380 |
|
| 3 |
liveuser |
5381 |
}#if end
|
| 226 |
liveuser |
5382 |
|
| 3 |
liveuser |
5383 |
#函式說明:
|
|
|
5384 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
5385 |
#回傳的結果:
|
|
|
5386 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5387 |
#$result["function"],當前執行的function名稱
|
|
|
5388 |
#$result["error"],錯誤訊息陣列.
|
|
|
5389 |
#$result["content"],處理好的字串.
|
|
|
5390 |
#$result["argu"],使用的參數.
|
|
|
5391 |
#必填參數:
|
|
|
5392 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
5393 |
$conf["arrays::arrayToString"]["inputArray"]=$str2bytesArray["content"];
|
|
|
5394 |
#可省略參數:
|
|
|
5395 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
5396 |
#$conf["spiltSymbol"]=";";
|
|
|
5397 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
5398 |
#$conf["skipEnd"]="";
|
|
|
5399 |
#參考資料:
|
|
|
5400 |
#無.
|
|
|
5401 |
#備註:
|
|
|
5402 |
#無.
|
|
|
5403 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
5404 |
unset($conf["arrays::arrayToString"]);
|
| 226 |
liveuser |
5405 |
|
| 3 |
liveuser |
5406 |
#如果執行失敗
|
|
|
5407 |
if($arrayToString["status"]==="false"){
|
| 226 |
liveuser |
5408 |
|
| 3 |
liveuser |
5409 |
#設置執行不正常
|
|
|
5410 |
$result["status"]="false";
|
| 226 |
liveuser |
5411 |
|
| 3 |
liveuser |
5412 |
#設置錯誤訊息
|
|
|
5413 |
$result["error"]=$arrayToString;
|
| 226 |
liveuser |
5414 |
|
| 3 |
liveuser |
5415 |
#回傳結果
|
|
|
5416 |
return $resutl;
|
| 226 |
liveuser |
5417 |
|
| 3 |
liveuser |
5418 |
}#if end
|
| 226 |
liveuser |
5419 |
|
| 3 |
liveuser |
5420 |
#設置執行正常
|
|
|
5421 |
$result["status"]="true";
|
| 226 |
liveuser |
5422 |
|
| 3 |
liveuser |
5423 |
#設置回傳的內容
|
|
|
5424 |
$result["content"]=$arrayToString["content"];
|
| 226 |
liveuser |
5425 |
|
| 3 |
liveuser |
5426 |
#回傳結果
|
|
|
5427 |
return $result;
|
| 226 |
liveuser |
5428 |
|
| 3 |
liveuser |
5429 |
}#function str2hexStr end
|
| 226 |
liveuser |
5430 |
|
| 3 |
liveuser |
5431 |
/*
|
|
|
5432 |
#函式說明:
|
|
|
5433 |
#將bytes數字(16進位)轉換為bit字串(0跟1來表述)
|
|
|
5434 |
#回傳結果:
|
|
|
5435 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5436 |
#$result["function"],當前執行的函式內容.
|
|
|
5437 |
#$result["error"],錯誤訊息陣列.
|
|
|
5438 |
#$result["content"],bit字串(0跟1來表述).
|
|
|
5439 |
#必填參數:
|
|
|
5440 |
#$conf["bytes"],字串,要轉換成bit的bytes數字.
|
|
|
5441 |
$conf["bytes"]="";
|
|
|
5442 |
#可省略參數:
|
|
|
5443 |
#無.
|
|
|
5444 |
#參考資料:
|
|
|
5445 |
#無.
|
|
|
5446 |
#備註:
|
|
|
5447 |
#無.
|
|
|
5448 |
*/
|
|
|
5449 |
public static function bytes2bitString(&$conf){
|
| 226 |
liveuser |
5450 |
|
| 3 |
liveuser |
5451 |
#初始化要回傳的結果
|
|
|
5452 |
$result=array();
|
|
|
5453 |
|
|
|
5454 |
#取得當前執行的函數名稱
|
|
|
5455 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5456 |
|
| 3 |
liveuser |
5457 |
#初始化結果
|
|
|
5458 |
$result["content"]=array();
|
|
|
5459 |
|
|
|
5460 |
#如果沒有參數
|
|
|
5461 |
if(func_num_args()==0){
|
| 226 |
liveuser |
5462 |
|
| 3 |
liveuser |
5463 |
#設置執行失敗
|
|
|
5464 |
$result["status"]="false";
|
| 226 |
liveuser |
5465 |
|
| 3 |
liveuser |
5466 |
#設置執行錯誤訊息
|
|
|
5467 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
5468 |
|
| 3 |
liveuser |
5469 |
#回傳結果
|
|
|
5470 |
return $result;
|
| 226 |
liveuser |
5471 |
|
| 3 |
liveuser |
5472 |
}#if end
|
|
|
5473 |
|
|
|
5474 |
#取得參數
|
|
|
5475 |
$result["argu"]=$conf;
|
|
|
5476 |
|
|
|
5477 |
#如果 $conf 不為陣列
|
|
|
5478 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
5479 |
|
| 3 |
liveuser |
5480 |
#設置執行失敗
|
|
|
5481 |
$result["status"]="false";
|
| 226 |
liveuser |
5482 |
|
| 3 |
liveuser |
5483 |
#設置執行錯誤訊息
|
|
|
5484 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
5485 |
|
| 3 |
liveuser |
5486 |
#如果傳入的參數為 null
|
|
|
5487 |
if($conf===null){
|
| 226 |
liveuser |
5488 |
|
| 3 |
liveuser |
5489 |
#設置執行錯誤訊息
|
|
|
5490 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
5491 |
|
| 3 |
liveuser |
5492 |
}#if end
|
|
|
5493 |
|
|
|
5494 |
#回傳結果
|
|
|
5495 |
return $result;
|
| 226 |
liveuser |
5496 |
|
| 3 |
liveuser |
5497 |
}#if end
|
| 226 |
liveuser |
5498 |
|
| 3 |
liveuser |
5499 |
#函式說明:
|
|
|
5500 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5501 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5502 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5503 |
#$result["function"],當前執行的函式名稱.
|
|
|
5504 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5505 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5506 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5507 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5508 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5509 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5510 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5511 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5512 |
#必填寫的參數:
|
|
|
5513 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5514 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5515 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5516 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("bytes");
|
|
|
5517 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
5518 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5519 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5520 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5521 |
#可以省略的參數:
|
|
|
5522 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5523 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
5524 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5525 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5526 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5527 |
#$conf["canBeEmpty"]=array();
|
|
|
5528 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5529 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5530 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5531 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
5532 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
5533 |
#$conf["skipableVariableType"]=array();
|
|
|
5534 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5535 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5536 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5537 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5538 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5539 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5540 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5541 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5542 |
#參考資料來源:
|
|
|
5543 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5544 |
#建議:
|
|
|
5545 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
5546 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5547 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5548 |
|
| 3 |
liveuser |
5549 |
#如果檢查參數失敗
|
|
|
5550 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5551 |
|
| 3 |
liveuser |
5552 |
#設置執行失敗
|
|
|
5553 |
$result["status"]="false";
|
| 226 |
liveuser |
5554 |
|
| 3 |
liveuser |
5555 |
#設置執行錯誤訊息
|
|
|
5556 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5557 |
|
| 3 |
liveuser |
5558 |
#回傳結果
|
|
|
5559 |
return $result;
|
| 226 |
liveuser |
5560 |
|
| 3 |
liveuser |
5561 |
}#if end
|
| 226 |
liveuser |
5562 |
|
| 3 |
liveuser |
5563 |
#如果檢查參數不通過
|
|
|
5564 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
5565 |
|
| 3 |
liveuser |
5566 |
#設置執行失敗
|
|
|
5567 |
$result["status"]="false";
|
| 226 |
liveuser |
5568 |
|
| 3 |
liveuser |
5569 |
#設置執行錯誤訊息
|
|
|
5570 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5571 |
|
| 3 |
liveuser |
5572 |
#回傳結果
|
|
|
5573 |
return $result;
|
| 226 |
liveuser |
5574 |
|
| 3 |
liveuser |
5575 |
}#if end
|
| 226 |
liveuser |
5576 |
|
| 3 |
liveuser |
5577 |
#儲存2進位數值
|
|
|
5578 |
$result["content"]=sprintf("%08s",base_convert($conf["bytes"],16,2));
|
| 226 |
liveuser |
5579 |
|
| 3 |
liveuser |
5580 |
#設置執行正常
|
|
|
5581 |
$result["status"]="true";
|
| 226 |
liveuser |
5582 |
|
| 3 |
liveuser |
5583 |
#回傳
|
|
|
5584 |
return $result;
|
| 226 |
liveuser |
5585 |
|
| 3 |
liveuser |
5586 |
}#function bytes2bitString end
|
| 226 |
liveuser |
5587 |
|
| 3 |
liveuser |
5588 |
/*
|
|
|
5589 |
#函式說明:
|
|
|
5590 |
#將2進位的8位數字字串,變成bytes字串.
|
|
|
5591 |
#回傳結果:
|
|
|
5592 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5593 |
#$result["function"],當前執行的函式內容.
|
|
|
5594 |
#$result["error"],錯誤訊息陣列.
|
|
|
5595 |
#$result["content"],bytes字串,亦即其代表的一個字.
|
|
|
5596 |
#必填參數:
|
|
|
5597 |
#$conf["8bits"],字串,要轉換成byte字串的bit數字字串,小於8位會於前頭補0,若非2進位的bit數字字串,則會報錯.
|
|
|
5598 |
$conf["8bits"]="00000000";
|
|
|
5599 |
#可省略參數:
|
|
|
5600 |
#無.
|
|
|
5601 |
#參考資料:
|
|
|
5602 |
#無.
|
|
|
5603 |
#備註:
|
|
|
5604 |
#無.
|
|
|
5605 |
*/
|
|
|
5606 |
public static function bit2byteStr($conf){
|
| 226 |
liveuser |
5607 |
|
| 3 |
liveuser |
5608 |
#初始化要回傳的結果
|
|
|
5609 |
$result=array();
|
|
|
5610 |
|
|
|
5611 |
#設置當其函數名稱
|
|
|
5612 |
$result["function"]=__FUNCTION__;
|
|
|
5613 |
|
|
|
5614 |
#如果 $conf 不為陣列
|
|
|
5615 |
if(gettype($conf)!="array"){
|
|
|
5616 |
|
|
|
5617 |
#設置執行失敗
|
|
|
5618 |
$result["status"]="false";
|
|
|
5619 |
|
|
|
5620 |
#設置執行錯誤訊息
|
|
|
5621 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5622 |
|
|
|
5623 |
#如果傳入的參數為 null
|
|
|
5624 |
if($conf==null){
|
|
|
5625 |
|
|
|
5626 |
#設置執行錯誤訊息
|
|
|
5627 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5628 |
|
|
|
5629 |
}#if end
|
|
|
5630 |
|
|
|
5631 |
#函式說明:
|
|
|
5632 |
#取得簡單的錯誤訊息
|
|
|
5633 |
#回傳結果:
|
|
|
5634 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5635 |
#$result["content"],結果.
|
|
|
5636 |
#$result["function"],當前執行的函數
|
|
|
5637 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
5638 |
#必填參數:
|
|
|
5639 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
5640 |
#$conf["error"],陣列,要處理的變數.
|
|
|
5641 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
5642 |
#可省略參數:
|
|
|
5643 |
#無
|
|
|
5644 |
#參考資料:
|
|
|
5645 |
#無.
|
|
|
5646 |
#備註:
|
|
|
5647 |
#無.
|
|
|
5648 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
5649 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
5650 |
|
|
|
5651 |
#如果執行失敗
|
|
|
5652 |
if($getSimpleError["status"]==="false"){
|
| 226 |
liveuser |
5653 |
|
| 3 |
liveuser |
5654 |
#設置執行錯誤訊息
|
|
|
5655 |
$result["error"][]=$getSimpleError;
|
| 226 |
liveuser |
5656 |
|
| 3 |
liveuser |
5657 |
#回傳結果
|
|
|
5658 |
return $result;
|
|
|
5659 |
|
|
|
5660 |
}#if end
|
|
|
5661 |
|
|
|
5662 |
#設置 $simpleError
|
|
|
5663 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
5664 |
|
|
|
5665 |
#回傳結果
|
|
|
5666 |
return $result;
|
|
|
5667 |
|
|
|
5668 |
}#if end
|
|
|
5669 |
|
|
|
5670 |
#設置放置的參數
|
|
|
5671 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
5672 |
|
| 3 |
liveuser |
5673 |
#函式說明:
|
|
|
5674 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
5675 |
#回傳結果:
|
|
|
5676 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5677 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
5678 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
5679 |
#$result["function"],當前執行的函式名稱.
|
|
|
5680 |
#$result["argu"],設置給予的參數.
|
|
|
5681 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5682 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5683 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5684 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5685 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5686 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5687 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5688 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5689 |
#必填參數:
|
|
|
5690 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5691 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5692 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5693 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5694 |
#可省略參數:
|
|
|
5695 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5696 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("8bits");
|
|
|
5697 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
5698 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5699 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5700 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5701 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5702 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5703 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5704 |
#$conf["canBeEmpty"]=array();
|
|
|
5705 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5706 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5707 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5708 |
#$conf["skipableVariableName"]=array();
|
|
|
5709 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5710 |
#$conf["skipableVariableType"]=array();
|
|
|
5711 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5712 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5713 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5714 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5715 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5716 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5717 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5718 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5719 |
#參考資料:
|
|
|
5720 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5721 |
#備註:
|
|
|
5722 |
#無.
|
|
|
5723 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5724 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5725 |
|
| 3 |
liveuser |
5726 |
#如果檢查參數失敗
|
|
|
5727 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5728 |
|
| 3 |
liveuser |
5729 |
#設置執行失敗
|
|
|
5730 |
$result["status"]="false";
|
| 226 |
liveuser |
5731 |
|
| 3 |
liveuser |
5732 |
#設置錯誤訊息陣列
|
|
|
5733 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5734 |
|
| 3 |
liveuser |
5735 |
#回傳結果
|
|
|
5736 |
return $result;
|
| 226 |
liveuser |
5737 |
|
| 3 |
liveuser |
5738 |
}#if end
|
| 226 |
liveuser |
5739 |
|
| 3 |
liveuser |
5740 |
#如果檢查參數不通過
|
|
|
5741 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5742 |
|
| 3 |
liveuser |
5743 |
#設置執行失敗
|
|
|
5744 |
$result["status"]="false";
|
| 226 |
liveuser |
5745 |
|
| 3 |
liveuser |
5746 |
#設置錯誤訊息陣列
|
|
|
5747 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5748 |
|
| 3 |
liveuser |
5749 |
#回傳結果
|
|
|
5750 |
return $result;
|
| 226 |
liveuser |
5751 |
|
| 3 |
liveuser |
5752 |
}#if end
|
| 226 |
liveuser |
5753 |
|
| 3 |
liveuser |
5754 |
#如果長度大於8
|
|
|
5755 |
if(strlen($conf["8bits"])>8){
|
| 226 |
liveuser |
5756 |
|
| 3 |
liveuser |
5757 |
#設置執行失敗
|
|
|
5758 |
$result["status"]="false";
|
| 226 |
liveuser |
5759 |
|
| 3 |
liveuser |
5760 |
#設置錯誤訊息陣列
|
|
|
5761 |
$result["error"][]="請確認為8bits字串";
|
| 226 |
liveuser |
5762 |
|
| 3 |
liveuser |
5763 |
#回傳結果
|
|
|
5764 |
return $result;
|
| 226 |
liveuser |
5765 |
|
| 3 |
liveuser |
5766 |
}#if end
|
| 226 |
liveuser |
5767 |
|
| 3 |
liveuser |
5768 |
#取得結果字串
|
|
|
5769 |
$result["content"]=chr(base_convert($conf["8bits"],2,10));
|
| 226 |
liveuser |
5770 |
|
| 3 |
liveuser |
5771 |
#設置執行正常
|
|
|
5772 |
$result["status"]="true";
|
| 226 |
liveuser |
5773 |
|
| 3 |
liveuser |
5774 |
#回傳結果
|
|
|
5775 |
return $result;
|
| 226 |
liveuser |
5776 |
|
| 3 |
liveuser |
5777 |
}#function bit2bytes end
|
| 226 |
liveuser |
5778 |
|
| 3 |
liveuser |
5779 |
/*
|
|
|
5780 |
#函式說明:
|
|
|
5781 |
#隨機產生任意byte(s)組成的字串.
|
|
|
5782 |
#回傳結果:
|
|
|
5783 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5784 |
#$result["function"],當前執行的函式內容.
|
|
|
5785 |
#$result["error"],錯誤訊息陣列.
|
|
|
5786 |
#$result["content"],用字串來表示的byte(s).
|
|
|
5787 |
#必填參數:
|
|
|
5788 |
#無.
|
|
|
5789 |
#可省略參數:
|
|
|
5790 |
#$conf["length"],字串,要產生多少bytes的字串,預設為1.
|
|
|
5791 |
#$conf["length"]="1";
|
|
|
5792 |
#參考資料:
|
|
|
5793 |
#無.
|
|
|
5794 |
#備註:
|
|
|
5795 |
#無.
|
|
|
5796 |
*/
|
|
|
5797 |
public static function randomByte(&$conf){
|
| 226 |
liveuser |
5798 |
|
| 3 |
liveuser |
5799 |
#初始化要回傳的結果
|
|
|
5800 |
$result=array();
|
|
|
5801 |
|
|
|
5802 |
#取得當前執行的函數名稱
|
|
|
5803 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5804 |
|
| 3 |
liveuser |
5805 |
#取得參數
|
|
|
5806 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
5807 |
|
| 3 |
liveuser |
5808 |
#如果 $conf 不為陣列
|
|
|
5809 |
if(gettype($conf)!="array"){
|
|
|
5810 |
|
|
|
5811 |
#設置執行失敗
|
|
|
5812 |
$result["status"]="false";
|
|
|
5813 |
|
|
|
5814 |
#設置執行錯誤訊息
|
|
|
5815 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5816 |
|
|
|
5817 |
#如果傳入的參數為 null
|
|
|
5818 |
if(is_null($conf)){
|
|
|
5819 |
|
|
|
5820 |
#設置執行錯誤訊息
|
|
|
5821 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5822 |
|
|
|
5823 |
}#if end
|
|
|
5824 |
|
|
|
5825 |
#回傳結果
|
|
|
5826 |
return $result;
|
|
|
5827 |
|
|
|
5828 |
}#if end
|
| 226 |
liveuser |
5829 |
|
| 3 |
liveuser |
5830 |
#函式說明:
|
|
|
5831 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
5832 |
#回傳結果:
|
|
|
5833 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5834 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
5835 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
5836 |
#$result["function"],當前執行的函式名稱.
|
|
|
5837 |
#$result["argu"],設置給予的參數.
|
|
|
5838 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5839 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5840 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5841 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5842 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5843 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5844 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5845 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5846 |
#必填參數:
|
|
|
5847 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5848 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5849 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5850 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5851 |
#可省略參數:
|
|
|
5852 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5853 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
5854 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
5855 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
5856 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5857 |
#$conf["canBeEmptyString"]="false";
|
|
|
5858 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5859 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5860 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5861 |
#$conf["canBeEmpty"]=array();
|
|
|
5862 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5863 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
|
|
|
5864 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5865 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
|
|
|
5866 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5867 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
5868 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5869 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1");
|
|
|
5870 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5871 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5872 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5873 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5874 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
5875 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
5876 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5877 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5878 |
#參考資料:
|
|
|
5879 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5880 |
#備註:
|
|
|
5881 |
#無.
|
|
|
5882 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5883 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5884 |
|
| 3 |
liveuser |
5885 |
#如果檢查參數失敗
|
|
|
5886 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5887 |
|
| 3 |
liveuser |
5888 |
#設置執行失敗
|
|
|
5889 |
$result["status"]="false";
|
| 226 |
liveuser |
5890 |
|
| 3 |
liveuser |
5891 |
#設置錯誤訊息陣列
|
|
|
5892 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5893 |
|
| 3 |
liveuser |
5894 |
#回傳結果
|
|
|
5895 |
return $result;
|
| 226 |
liveuser |
5896 |
|
| 3 |
liveuser |
5897 |
}#if end
|
| 226 |
liveuser |
5898 |
|
| 3 |
liveuser |
5899 |
#如果檢查參數不通過
|
|
|
5900 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5901 |
|
| 3 |
liveuser |
5902 |
#設置執行失敗
|
|
|
5903 |
$result["status"]="false";
|
| 226 |
liveuser |
5904 |
|
| 3 |
liveuser |
5905 |
#設置錯誤訊息陣列
|
|
|
5906 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5907 |
|
| 3 |
liveuser |
5908 |
#回傳結果
|
|
|
5909 |
return $result;
|
| 226 |
liveuser |
5910 |
|
| 3 |
liveuser |
5911 |
}#if end
|
| 226 |
liveuser |
5912 |
|
| 3 |
liveuser |
5913 |
#初始化儲存用字串來表示的byte(s).
|
|
|
5914 |
$result["content"]="";
|
| 226 |
liveuser |
5915 |
|
| 3 |
liveuser |
5916 |
#要多少bytes就跑幾次
|
|
|
5917 |
for($i=0;$i<$conf["length"];$i++){
|
| 226 |
liveuser |
5918 |
|
| 3 |
liveuser |
5919 |
#暫存byte
|
|
|
5920 |
$byte="";
|
| 226 |
liveuser |
5921 |
|
| 3 |
liveuser |
5922 |
#隨機產生該byte開始bit不為0的位置
|
|
|
5923 |
$bitNotZeroAddr=\rand(0,7);
|
| 226 |
liveuser |
5924 |
|
| 3 |
liveuser |
5925 |
#每個bit都跑一次
|
|
|
5926 |
for($j=0;$j<8;$j++){
|
| 226 |
liveuser |
5927 |
|
| 3 |
liveuser |
5928 |
#如果還沒開始有資料
|
|
|
5929 |
if($j<$bitNotZeroAddr){
|
| 226 |
liveuser |
5930 |
|
| 3 |
liveuser |
5931 |
#加0
|
|
|
5932 |
$byte=$byte."0";
|
| 226 |
liveuser |
5933 |
|
| 3 |
liveuser |
5934 |
#下一個迴圈
|
|
|
5935 |
continue;
|
| 226 |
liveuser |
5936 |
|
| 3 |
liveuser |
5937 |
}#if end
|
| 226 |
liveuser |
5938 |
|
| 3 |
liveuser |
5939 |
#隨機產生bit
|
|
|
5940 |
$bit=\rand(0,1);
|
| 226 |
liveuser |
5941 |
|
| 3 |
liveuser |
5942 |
#加bit
|
|
|
5943 |
$byte=$byte.(string)($bit);
|
| 226 |
liveuser |
5944 |
|
| 3 |
liveuser |
5945 |
}#for end
|
| 226 |
liveuser |
5946 |
|
| 3 |
liveuser |
5947 |
#用字串來表示byte
|
|
|
5948 |
$byte=chr(base_convert($byte,2,10));
|
| 226 |
liveuser |
5949 |
|
| 3 |
liveuser |
5950 |
#串接byte
|
|
|
5951 |
$result["content"]=$result["content"].$byte;
|
| 226 |
liveuser |
5952 |
|
| 3 |
liveuser |
5953 |
}#for end
|
| 226 |
liveuser |
5954 |
|
| 3 |
liveuser |
5955 |
#設置執行正常
|
|
|
5956 |
$result["status"]="true";
|
| 226 |
liveuser |
5957 |
|
| 3 |
liveuser |
5958 |
#回傳結果
|
|
|
5959 |
return $result;
|
| 226 |
liveuser |
5960 |
|
| 3 |
liveuser |
5961 |
}#function randomByte end
|
| 226 |
liveuser |
5962 |
|
| 3 |
liveuser |
5963 |
/*
|
|
|
5964 |
#函式說明:
|
|
|
5965 |
#判斷字串是否一定需要經過escapeshellarg才能為單一shell參數,並回傳可以成為單一shell參數的結果.
|
|
|
5966 |
#回傳結果:
|
|
|
5967 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5968 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5969 |
#$result["function"],當前執行的函式名稱.
|
|
|
5970 |
#$result["argu"],使用的參數.
|
|
|
5971 |
#$result["content"],字串,單一shell參數.
|
|
|
5972 |
#$result["required"],字串,"true"代表content為 escape後的結果;反之為"false".
|
|
|
5973 |
#$result["urlEncodeStr"],字串,未被escape過的單一shell參數被url encode後的結果.
|
|
|
5974 |
#必填參數:
|
|
|
5975 |
#$conf["str"],字串,認為要為單一 shell參數的字串.
|
|
|
5976 |
#$conf["str"]="";
|
|
|
5977 |
#可省略參數:
|
|
|
5978 |
#無.
|
|
|
5979 |
#參考資料:
|
|
|
5980 |
#無.
|
|
|
5981 |
#備註:
|
|
|
5982 |
#無.
|
|
|
5983 |
*/
|
|
|
5984 |
public static function toSingleShellArg(&$conf){
|
| 226 |
liveuser |
5985 |
|
| 3 |
liveuser |
5986 |
#初始化要回傳的結果
|
|
|
5987 |
$result=array();
|
|
|
5988 |
|
|
|
5989 |
#取得當前執行的函數名稱
|
|
|
5990 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5991 |
|
| 3 |
liveuser |
5992 |
#取得參數
|
|
|
5993 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
5994 |
|
| 3 |
liveuser |
5995 |
#如果 $conf 不為陣列
|
|
|
5996 |
if(gettype($conf)!="array"){
|
|
|
5997 |
|
|
|
5998 |
#設置執行失敗
|
|
|
5999 |
$result["status"]="false";
|
|
|
6000 |
|
|
|
6001 |
#設置執行錯誤訊息
|
|
|
6002 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
6003 |
|
|
|
6004 |
#如果傳入的參數為 null
|
|
|
6005 |
if(is_null($conf)){
|
|
|
6006 |
|
|
|
6007 |
#設置執行錯誤訊息
|
|
|
6008 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
6009 |
|
|
|
6010 |
}#if end
|
|
|
6011 |
|
|
|
6012 |
#回傳結果
|
|
|
6013 |
return $result;
|
|
|
6014 |
|
|
|
6015 |
}#if end
|
| 226 |
liveuser |
6016 |
|
| 3 |
liveuser |
6017 |
#檢查參數
|
|
|
6018 |
#函式說明:
|
|
|
6019 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
6020 |
#回傳結果:
|
|
|
6021 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6022 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
6023 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
6024 |
#$result["function"],當前執行的函式名稱.
|
|
|
6025 |
#$result["argu"],設置給予的參數.
|
|
|
6026 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
6027 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
6028 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
6029 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
6030 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
6031 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
6032 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
6033 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
6034 |
#必填參數:
|
|
|
6035 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 220 |
liveuser |
6036 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
6037 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
| 220 |
liveuser |
6038 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
| 3 |
liveuser |
6039 |
#可省略參數:
|
|
|
6040 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
| 220 |
liveuser |
6041 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("str");
|
| 3 |
liveuser |
6042 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
| 220 |
liveuser |
6043 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
| 3 |
liveuser |
6044 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
6045 |
#$conf["canBeEmptyString"]="false";
|
|
|
6046 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
6047 |
#$conf["canNotBeEmpty"]=array();
|
|
|
6048 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
6049 |
#$conf["canBeEmpty"]=array();
|
|
|
6050 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
6051 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
6052 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
6053 |
#$conf["skipableVariableName"]=array();
|
|
|
6054 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
6055 |
#$conf["skipableVariableType"]=array();
|
|
|
6056 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
6057 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
6058 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
6059 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
6060 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
6061 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
6062 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
6063 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
6064 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
6065 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
6066 |
#參考資料:
|
|
|
6067 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
6068 |
#備註:
|
|
|
6069 |
#無.
|
| 220 |
liveuser |
6070 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 3 |
liveuser |
6071 |
unset($conf["variable::checkArguments"]);
|
| 226 |
liveuser |
6072 |
|
| 3 |
liveuser |
6073 |
#如果檢查參數失敗
|
|
|
6074 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
6075 |
|
| 3 |
liveuser |
6076 |
#設置執行失敗
|
|
|
6077 |
$result["status"]="false";
|
| 226 |
liveuser |
6078 |
|
| 3 |
liveuser |
6079 |
#設置錯誤訊息陣列
|
|
|
6080 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
6081 |
|
| 3 |
liveuser |
6082 |
#回傳結果
|
|
|
6083 |
return $result;
|
| 226 |
liveuser |
6084 |
|
| 3 |
liveuser |
6085 |
}#if end
|
| 226 |
liveuser |
6086 |
|
| 3 |
liveuser |
6087 |
#如果檢查參數不通過
|
| 220 |
liveuser |
6088 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
6089 |
|
| 3 |
liveuser |
6090 |
#設置執行失敗
|
|
|
6091 |
$result["status"]="false";
|
| 226 |
liveuser |
6092 |
|
| 3 |
liveuser |
6093 |
#設置錯誤訊息陣列
|
|
|
6094 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
6095 |
|
| 3 |
liveuser |
6096 |
#回傳結果
|
|
|
6097 |
return $result;
|
| 226 |
liveuser |
6098 |
|
| 3 |
liveuser |
6099 |
}#if end
|
| 226 |
liveuser |
6100 |
|
| 3 |
liveuser |
6101 |
#取得 str 的 bytes 數
|
|
|
6102 |
$strLength=strlen($conf["str"]);
|
| 226 |
liveuser |
6103 |
|
| 3 |
liveuser |
6104 |
#初始化 url encode 後的 str 參數
|
|
|
6105 |
$result["urlEncodeStr"]="";
|
| 226 |
liveuser |
6106 |
|
| 3 |
liveuser |
6107 |
#如果不是空字串
|
|
|
6108 |
if($strLength!==0){
|
| 226 |
liveuser |
6109 |
|
| 220 |
liveuser |
6110 |
#函式說明:
|
|
|
6111 |
#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
|
|
|
6112 |
#回傳結果:
|
|
|
6113 |
#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
|
|
|
6114 |
#$result["function"],當前執行的函數.
|
|
|
6115 |
#$result["error"],錯誤訊息陣列.
|
|
|
6116 |
#$result["argu"],使用者參數.
|
|
|
6117 |
#$result["changedPath"],處理完後回傳的目錄字串.
|
|
|
6118 |
#$result["oriPath"],原始的路徑字串
|
|
|
6119 |
#必填參數:
|
|
|
6120 |
#$conf["dirStr"],字串,要處理的檔案目錄字串.
|
|
|
6121 |
$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=pathinfo(__FILE__)["dirname"]."/../../bin/parse";
|
|
|
6122 |
#可省略參數:
|
|
|
6123 |
#無.
|
|
|
6124 |
#參考資料:
|
|
|
6125 |
#無.
|
|
|
6126 |
#備註:
|
|
|
6127 |
#考慮用realpath取代
|
|
|
6128 |
$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
|
|
|
6129 |
unset($conf["stringProcess::changeDirByDotDotSolidus"]);
|
| 226 |
liveuser |
6130 |
|
| 220 |
liveuser |
6131 |
#如果檢查參數失敗
|
|
|
6132 |
if($changeDirByDotDotSolidus["status"]==="false"){
|
| 226 |
liveuser |
6133 |
|
| 220 |
liveuser |
6134 |
#設置執行失敗
|
|
|
6135 |
$result["status"]="false";
|
| 226 |
liveuser |
6136 |
|
| 220 |
liveuser |
6137 |
#設置錯誤訊息陣列
|
|
|
6138 |
$result["error"]=$changeDirByDotDotSolidus;
|
| 226 |
liveuser |
6139 |
|
| 220 |
liveuser |
6140 |
#回傳結果
|
|
|
6141 |
return $result;
|
| 226 |
liveuser |
6142 |
|
| 220 |
liveuser |
6143 |
}#if end
|
| 226 |
liveuser |
6144 |
|
|
|
6145 |
#設置要執行的指令
|
| 220 |
liveuser |
6146 |
$cmd=escapeshellarg($changeDirByDotDotSolidus["changedPath"])." ".$conf["str"];
|
| 226 |
liveuser |
6147 |
|
| 3 |
liveuser |
6148 |
#執行指令
|
|
|
6149 |
exec($cmd,$output,$status);
|
| 226 |
liveuser |
6150 |
|
| 3 |
liveuser |
6151 |
#如果執行失敗
|
|
|
6152 |
if($status!==0){
|
| 226 |
liveuser |
6153 |
|
| 3 |
liveuser |
6154 |
#設置執行失敗
|
|
|
6155 |
$result["status"]="false";
|
| 226 |
liveuser |
6156 |
|
| 3 |
liveuser |
6157 |
#設置錯誤訊息陣列
|
|
|
6158 |
$result["error"][]="run command(".$cmd.") failed!";
|
| 226 |
liveuser |
6159 |
|
| 3 |
liveuser |
6160 |
#回傳結果
|
|
|
6161 |
return $result;
|
| 226 |
liveuser |
6162 |
|
| 3 |
liveuser |
6163 |
}#if end
|
| 226 |
liveuser |
6164 |
|
| 3 |
liveuser |
6165 |
#如果沒有輸出
|
|
|
6166 |
if(count($output)<1){
|
| 226 |
liveuser |
6167 |
|
| 3 |
liveuser |
6168 |
#設置執行失敗
|
|
|
6169 |
$result["status"]="false";
|
| 226 |
liveuser |
6170 |
|
| 3 |
liveuser |
6171 |
#設置錯誤訊息陣列
|
|
|
6172 |
$result["error"][]="no output from command(".$cmd.")";
|
| 226 |
liveuser |
6173 |
|
| 3 |
liveuser |
6174 |
#回傳結果
|
|
|
6175 |
return $result;
|
| 226 |
liveuser |
6176 |
|
| 3 |
liveuser |
6177 |
}#if end
|
| 226 |
liveuser |
6178 |
|
| 3 |
liveuser |
6179 |
#如果輸出不是 json
|
|
|
6180 |
if(json_validate($output[0])===false){
|
| 226 |
liveuser |
6181 |
|
| 3 |
liveuser |
6182 |
#設置執行失敗
|
|
|
6183 |
$result["status"]="false";
|
| 226 |
liveuser |
6184 |
|
| 3 |
liveuser |
6185 |
#設置錯誤訊息陣列
|
|
|
6186 |
$result["error"][]="output from command(".$cmd.") is not json";
|
| 226 |
liveuser |
6187 |
|
| 3 |
liveuser |
6188 |
#回傳結果
|
|
|
6189 |
return $result;
|
| 226 |
liveuser |
6190 |
|
| 3 |
liveuser |
6191 |
}#if end
|
| 226 |
liveuser |
6192 |
|
| 3 |
liveuser |
6193 |
#array of json decode
|
|
|
6194 |
$resArray=(array)(json_decode($output[0]));
|
| 226 |
liveuser |
6195 |
|
| 3 |
liveuser |
6196 |
#如果解析出來的元素數量不為2
|
|
|
6197 |
if(count($resArray)!==2){
|
| 226 |
liveuser |
6198 |
|
| 3 |
liveuser |
6199 |
#設置需要 escape
|
|
|
6200 |
$result["required"]="true";
|
| 226 |
liveuser |
6201 |
|
| 3 |
liveuser |
6202 |
#設置 content 為原始內容
|
|
|
6203 |
$result["content"]=escapeshellarg($conf["str"]);
|
| 226 |
liveuser |
6204 |
|
| 42 |
liveuser |
6205 |
#設置url encode後的內容
|
|
|
6206 |
$result["urlEncodeStr"]=urlencode($conf["str"]);
|
| 226 |
liveuser |
6207 |
|
| 3 |
liveuser |
6208 |
#設置執行正常
|
|
|
6209 |
$result["status"]="true";
|
| 226 |
liveuser |
6210 |
|
| 3 |
liveuser |
6211 |
#回傳結果
|
|
|
6212 |
return $result;
|
| 226 |
liveuser |
6213 |
|
| 3 |
liveuser |
6214 |
}#if end
|
| 226 |
liveuser |
6215 |
|
| 3 |
liveuser |
6216 |
#反之,有被解析成單一 shell參數
|
|
|
6217 |
else{
|
|
|
6218 |
|
|
|
6219 |
#如果開頭跟結尾是"'"
|
|
|
6220 |
if( $conf["str"][0]==="'" && $conf["str"][$strLength-1]==="'"){
|
| 226 |
liveuser |
6221 |
|
| 3 |
liveuser |
6222 |
#剔除前面的"'"
|
|
|
6223 |
$altStr=substr($conf["str"],1);
|
| 226 |
liveuser |
6224 |
|
| 3 |
liveuser |
6225 |
#剔除後面的"'"
|
|
|
6226 |
$altStr=substr($altStr,0,strlen($altStr)-1);
|
| 226 |
liveuser |
6227 |
|
|
|
6228 |
#設置要執行的指令
|
| 3 |
liveuser |
6229 |
$cmd=escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../bin/parse")." ".$altStr;
|
| 226 |
liveuser |
6230 |
|
| 3 |
liveuser |
6231 |
#執行指令
|
|
|
6232 |
exec($cmd,$output,$status);
|
| 226 |
liveuser |
6233 |
|
| 3 |
liveuser |
6234 |
#如果執行失敗
|
|
|
6235 |
if($status!==0){
|
| 226 |
liveuser |
6236 |
|
| 3 |
liveuser |
6237 |
#設置執行失敗
|
|
|
6238 |
$result["status"]="false";
|
| 226 |
liveuser |
6239 |
|
| 3 |
liveuser |
6240 |
#設置錯誤訊息陣列
|
|
|
6241 |
$result["error"][]="run command(".$cmd.") failed!";
|
| 226 |
liveuser |
6242 |
|
| 220 |
liveuser |
6243 |
#設置錯誤訊息陣列
|
|
|
6244 |
$result["error"][]="output:".print_r($output,true);
|
| 226 |
liveuser |
6245 |
|
| 3 |
liveuser |
6246 |
#回傳結果
|
|
|
6247 |
return $result;
|
| 226 |
liveuser |
6248 |
|
| 3 |
liveuser |
6249 |
}#if end
|
| 226 |
liveuser |
6250 |
|
| 3 |
liveuser |
6251 |
#如果沒有輸出
|
|
|
6252 |
if(count($output)<1){
|
| 226 |
liveuser |
6253 |
|
| 3 |
liveuser |
6254 |
#設置執行失敗
|
|
|
6255 |
$result["status"]="false";
|
| 226 |
liveuser |
6256 |
|
| 3 |
liveuser |
6257 |
#設置錯誤訊息陣列
|
|
|
6258 |
$result["error"][]="no output from command(".$cmd.")";
|
| 226 |
liveuser |
6259 |
|
| 3 |
liveuser |
6260 |
#回傳結果
|
|
|
6261 |
return $result;
|
| 226 |
liveuser |
6262 |
|
| 3 |
liveuser |
6263 |
}#if end
|
| 226 |
liveuser |
6264 |
|
| 3 |
liveuser |
6265 |
#如果輸出不是 json
|
|
|
6266 |
if(json_validate($output[0])===false){
|
| 226 |
liveuser |
6267 |
|
| 3 |
liveuser |
6268 |
#設置執行失敗
|
|
|
6269 |
$result["status"]="false";
|
| 226 |
liveuser |
6270 |
|
| 3 |
liveuser |
6271 |
#設置錯誤訊息陣列
|
|
|
6272 |
$result["error"][]="output from command(".$cmd.") is not json";
|
| 226 |
liveuser |
6273 |
|
| 3 |
liveuser |
6274 |
#回傳結果
|
|
|
6275 |
return $result;
|
| 226 |
liveuser |
6276 |
|
| 3 |
liveuser |
6277 |
}#if end
|
| 226 |
liveuser |
6278 |
|
| 3 |
liveuser |
6279 |
#array of json decode
|
|
|
6280 |
$resArray=(array)(json_decode($output[0]));
|
| 226 |
liveuser |
6281 |
|
| 3 |
liveuser |
6282 |
#如果解析出來的元素數量不為2
|
|
|
6283 |
if(count($resArray)!==2){
|
| 226 |
liveuser |
6284 |
|
| 3 |
liveuser |
6285 |
#設置需要 escape
|
|
|
6286 |
$result["required"]="true";
|
| 226 |
liveuser |
6287 |
|
| 3 |
liveuser |
6288 |
#設置 content 為原始內容
|
|
|
6289 |
$result["content"]=$conf["str"];
|
| 226 |
liveuser |
6290 |
|
| 3 |
liveuser |
6291 |
#設置取得 shell arg 的指令
|
|
|
6292 |
$cmd=escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../bin/parse")." ".$result["content"];
|
| 226 |
liveuser |
6293 |
|
| 3 |
liveuser |
6294 |
#初始化輸出
|
|
|
6295 |
$output=array();
|
| 226 |
liveuser |
6296 |
|
| 3 |
liveuser |
6297 |
#執行指令
|
|
|
6298 |
exec($cmd,$output,$status);
|
| 226 |
liveuser |
6299 |
|
| 3 |
liveuser |
6300 |
#如果執行失敗
|
|
|
6301 |
if($status!==0){
|
| 226 |
liveuser |
6302 |
|
| 3 |
liveuser |
6303 |
#設置執行失敗
|
|
|
6304 |
$result["status"]="false";
|
| 226 |
liveuser |
6305 |
|
| 3 |
liveuser |
6306 |
#設置錯誤訊息陣列
|
|
|
6307 |
$result["error"][]="run command(".$cmd.") failed!";
|
| 226 |
liveuser |
6308 |
|
| 3 |
liveuser |
6309 |
#回傳結果
|
|
|
6310 |
return $result;
|
| 226 |
liveuser |
6311 |
|
| 3 |
liveuser |
6312 |
}#if end
|
| 226 |
liveuser |
6313 |
|
| 3 |
liveuser |
6314 |
#如果沒有輸出
|
|
|
6315 |
if(count($output)<1){
|
| 226 |
liveuser |
6316 |
|
| 3 |
liveuser |
6317 |
#設置執行失敗
|
|
|
6318 |
$result["status"]="false";
|
| 226 |
liveuser |
6319 |
|
| 3 |
liveuser |
6320 |
#設置錯誤訊息陣列
|
|
|
6321 |
$result["error"][]="no output from command(".$cmd.")";
|
| 226 |
liveuser |
6322 |
|
| 3 |
liveuser |
6323 |
#回傳結果
|
|
|
6324 |
return $result;
|
| 226 |
liveuser |
6325 |
|
| 3 |
liveuser |
6326 |
}#if end
|
| 226 |
liveuser |
6327 |
|
| 3 |
liveuser |
6328 |
#如果輸出不是 json
|
|
|
6329 |
if(json_validate($output[0])===false){
|
| 226 |
liveuser |
6330 |
|
| 3 |
liveuser |
6331 |
#設置執行失敗
|
|
|
6332 |
$result["status"]="false";
|
| 226 |
liveuser |
6333 |
|
| 3 |
liveuser |
6334 |
#設置錯誤訊息陣列
|
|
|
6335 |
$result["error"][]="output from command(".$cmd.") is not json";
|
| 226 |
liveuser |
6336 |
|
| 3 |
liveuser |
6337 |
#回傳結果
|
|
|
6338 |
return $result;
|
| 226 |
liveuser |
6339 |
|
| 3 |
liveuser |
6340 |
}#if end
|
| 226 |
liveuser |
6341 |
|
| 3 |
liveuser |
6342 |
#array of json decode
|
|
|
6343 |
$resArray=(array)(json_decode($output[0]));
|
| 226 |
liveuser |
6344 |
|
| 3 |
liveuser |
6345 |
#如果解析出來的元素數量不為2
|
|
|
6346 |
if(count($resArray)!==2){
|
| 226 |
liveuser |
6347 |
|
| 3 |
liveuser |
6348 |
#設置執行失敗
|
|
|
6349 |
$result["status"]="false";
|
| 226 |
liveuser |
6350 |
|
| 3 |
liveuser |
6351 |
#設置錯誤訊息陣列
|
|
|
6352 |
$result["error"][]="output from command(".$cmd.") is not valid";
|
| 226 |
liveuser |
6353 |
|
| 3 |
liveuser |
6354 |
#回傳結果
|
|
|
6355 |
return $result;
|
| 226 |
liveuser |
6356 |
|
| 3 |
liveuser |
6357 |
}#if end
|
| 226 |
liveuser |
6358 |
|
| 3 |
liveuser |
6359 |
#設置url encode後的內容
|
|
|
6360 |
$result["urlEncodeStr"]=urlencode($resArray[1]);
|
| 226 |
liveuser |
6361 |
|
| 3 |
liveuser |
6362 |
}#if end
|
| 226 |
liveuser |
6363 |
|
| 3 |
liveuser |
6364 |
#反之
|
|
|
6365 |
else{
|
| 226 |
liveuser |
6366 |
|
| 3 |
liveuser |
6367 |
#設置不需要 escape
|
|
|
6368 |
$result["required"]="false";
|
| 226 |
liveuser |
6369 |
|
| 3 |
liveuser |
6370 |
#設置 content 為未 escape 的內容
|
|
|
6371 |
$result["content"]=$altStr;
|
| 226 |
liveuser |
6372 |
|
| 3 |
liveuser |
6373 |
#設置url encode後的內容
|
|
|
6374 |
$result["urlEncodeStr"]=urlencode($result["content"]);
|
| 226 |
liveuser |
6375 |
|
| 3 |
liveuser |
6376 |
}#else end
|
| 226 |
liveuser |
6377 |
|
| 3 |
liveuser |
6378 |
}#if end
|
| 226 |
liveuser |
6379 |
|
| 3 |
liveuser |
6380 |
#反之
|
|
|
6381 |
else{
|
| 226 |
liveuser |
6382 |
|
| 3 |
liveuser |
6383 |
#設置不需要 escape
|
|
|
6384 |
$result["required"]="false";
|
| 226 |
liveuser |
6385 |
|
| 3 |
liveuser |
6386 |
#設置 content 為 str 的內容
|
|
|
6387 |
$result["content"]=$conf["str"];
|
| 226 |
liveuser |
6388 |
|
| 3 |
liveuser |
6389 |
#設置url encode後的內容
|
|
|
6390 |
$result["urlEncodeStr"]=urlencode($result["content"]);
|
| 226 |
liveuser |
6391 |
|
| 3 |
liveuser |
6392 |
}#else end
|
| 226 |
liveuser |
6393 |
|
| 3 |
liveuser |
6394 |
}#else end
|
| 226 |
liveuser |
6395 |
|
| 3 |
liveuser |
6396 |
}#if end
|
| 226 |
liveuser |
6397 |
|
|
|
6398 |
#反之
|
| 3 |
liveuser |
6399 |
else{
|
| 226 |
liveuser |
6400 |
|
| 3 |
liveuser |
6401 |
#設置需要 escape
|
|
|
6402 |
$result["required"]="true";
|
| 226 |
liveuser |
6403 |
|
| 3 |
liveuser |
6404 |
#設置 content 為原始內容
|
|
|
6405 |
$result["content"]=escapeshellarg("");
|
| 226 |
liveuser |
6406 |
|
| 3 |
liveuser |
6407 |
}#else end
|
|
|
6408 |
|
|
|
6409 |
#設置執行正常
|
|
|
6410 |
$result["status"]="true";
|
|
|
6411 |
|
|
|
6412 |
#回傳結果
|
|
|
6413 |
return $result;
|
|
|
6414 |
|
|
|
6415 |
}#function toSingleShellArg end
|
| 226 |
liveuser |
6416 |
|
| 3 |
liveuser |
6417 |
}#class stringProcess end
|
|
|
6418 |
|
|
|
6419 |
?>
|