| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 226 |
liveuser |
6 |
Copyright (C) 2014~2025 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
|
|
|
48 |
#備註:
|
|
|
49 |
#無.
|
|
|
50 |
*/
|
|
|
51 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
52 |
|
| 3 |
liveuser |
53 |
#取得當前執行的函式
|
|
|
54 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
55 |
|
| 3 |
liveuser |
56 |
#設置執行不正常
|
|
|
57 |
$result["status"]="false";
|
| 226 |
liveuser |
58 |
|
| 3 |
liveuser |
59 |
#設置執行錯誤
|
|
|
60 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
61 |
|
| 3 |
liveuser |
62 |
#設置所丟入的參數
|
|
|
63 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
64 |
|
| 3 |
liveuser |
65 |
#回傳結果
|
|
|
66 |
return $result;
|
| 226 |
liveuser |
67 |
|
| 3 |
liveuser |
68 |
}#function __call end
|
| 226 |
liveuser |
69 |
|
| 3 |
liveuser |
70 |
/*
|
|
|
71 |
#函式說明:
|
|
|
72 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
73 |
#回傳結果:
|
|
|
74 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
76 |
#$result["function"],當前執行的函式名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
79 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
80 |
#可省略參數:
|
|
|
81 |
#無.
|
|
|
82 |
#參考資料:
|
|
|
83 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
84 |
#備註:
|
|
|
85 |
#無.
|
|
|
86 |
*/
|
|
|
87 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
88 |
|
| 3 |
liveuser |
89 |
#取得當前執行的函式
|
|
|
90 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
91 |
|
| 3 |
liveuser |
92 |
#設置執行不正常
|
|
|
93 |
$result["status"]="false";
|
| 226 |
liveuser |
94 |
|
| 3 |
liveuser |
95 |
#設置執行錯誤
|
|
|
96 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
97 |
|
| 3 |
liveuser |
98 |
#設置所丟入的參數
|
|
|
99 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
100 |
|
| 3 |
liveuser |
101 |
#回傳結果
|
|
|
102 |
return $result;
|
| 226 |
liveuser |
103 |
|
| 3 |
liveuser |
104 |
}#function __callStatic end
|
| 226 |
liveuser |
105 |
|
| 3 |
liveuser |
106 |
/*
|
|
|
107 |
#函式說明:
|
|
|
108 |
#將含有數個黑點的字串,處理成只剩下含有最後一個黑點的字串,結果會回傳合併後的字串。
|
|
|
109 |
#如果字串中沒有黑點則會回傳原始字串
|
|
|
110 |
#回傳結果:
|
|
|
111 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
112 |
#$result["error"],錯誤訊息陣列
|
|
|
113 |
#$result["function"],當前函數名稱
|
|
|
114 |
#$result["content"],只剩下最後一個黑點的字串
|
|
|
115 |
#必填參數:
|
|
|
116 |
#$conf["stringIn"],字串,爲要進行處理的字串
|
|
|
117 |
$conf["stringIn"]="";
|
|
|
118 |
#可省略參數:
|
|
|
119 |
#無.
|
|
|
120 |
#參考資料:
|
|
|
121 |
#無.
|
|
|
122 |
#備註:
|
|
|
123 |
#無.
|
|
|
124 |
*/
|
|
|
125 |
public static function solveDotProblems(&$conf){
|
|
|
126 |
|
|
|
127 |
#初始化要回傳的內容
|
|
|
128 |
$result=array();
|
| 226 |
liveuser |
129 |
|
| 3 |
liveuser |
130 |
#取得當前函數名稱
|
|
|
131 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
132 |
|
| 3 |
liveuser |
133 |
#如果 $conf 不為陣列
|
|
|
134 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
135 |
|
| 3 |
liveuser |
136 |
#設置執行失敗
|
|
|
137 |
$result["status"]="false";
|
| 226 |
liveuser |
138 |
|
| 3 |
liveuser |
139 |
#設置執行錯誤訊息
|
|
|
140 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
141 |
|
| 3 |
liveuser |
142 |
#如果傳入的參數為 null
|
|
|
143 |
if($conf==null){
|
| 226 |
liveuser |
144 |
|
| 3 |
liveuser |
145 |
#設置執行錯誤訊息
|
|
|
146 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
147 |
|
| 3 |
liveuser |
148 |
}#if end
|
| 226 |
liveuser |
149 |
|
| 3 |
liveuser |
150 |
#回傳結果
|
|
|
151 |
return $result;
|
| 226 |
liveuser |
152 |
|
| 3 |
liveuser |
153 |
}#if end
|
| 226 |
liveuser |
154 |
|
| 3 |
liveuser |
155 |
#初始化要回傳的語法
|
|
|
156 |
$result["content"]="";
|
|
|
157 |
|
|
|
158 |
#檢查參數
|
|
|
159 |
#函式說明:
|
|
|
160 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
161 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
162 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
163 |
#$result["function"],當前執行的函式名稱.
|
|
|
164 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
165 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
166 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
167 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
168 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
169 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
170 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
171 |
#必填寫的參數:
|
|
|
172 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
173 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
174 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
175 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
176 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
177 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
178 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
179 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
180 |
#可以省略的參數:
|
|
|
181 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
182 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
183 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
184 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("ssl","serverIp","port");
|
| 226 |
liveuser |
185 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
186 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
187 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
188 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true","127.0.0.1",null);
|
|
|
189 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
190 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
191 |
#參考資料來源:
|
|
|
192 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
193 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
194 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
195 |
|
| 3 |
liveuser |
196 |
#如果檢查失敗
|
|
|
197 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
198 |
|
| 3 |
liveuser |
199 |
#設置執行不正常
|
|
|
200 |
$result["status"]="false";
|
| 226 |
liveuser |
201 |
|
| 3 |
liveuser |
202 |
#設置錯誤訊息
|
|
|
203 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
204 |
|
| 3 |
liveuser |
205 |
#回傳結果
|
|
|
206 |
return $result;
|
| 226 |
liveuser |
207 |
|
| 3 |
liveuser |
208 |
}#if end
|
| 226 |
liveuser |
209 |
|
| 3 |
liveuser |
210 |
#如果檢查不通過
|
|
|
211 |
if($checkResult["passed"]=="false"){
|
|
|
212 |
|
|
|
213 |
#設置執行不正常
|
|
|
214 |
$result["status"]="false";
|
| 226 |
liveuser |
215 |
|
| 3 |
liveuser |
216 |
#設置錯誤訊息
|
|
|
217 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
218 |
|
| 3 |
liveuser |
219 |
#回傳結果
|
|
|
220 |
return $result;
|
|
|
221 |
|
|
|
222 |
}#if end
|
|
|
223 |
|
|
|
224 |
#宣告$str為string
|
|
|
225 |
$str = "";
|
|
|
226 |
|
|
|
227 |
#取得該字串有幾個"."
|
| 226 |
liveuser |
228 |
$numberDot = substr_count($conf["stringIn"],".");
|
|
|
229 |
|
| 3 |
liveuser |
230 |
#開始分離
|
|
|
231 |
$changedString = explode(".",$conf["stringIn"]);
|
|
|
232 |
|
|
|
233 |
#開始重組
|
|
|
234 |
for($i=0;$i<=($numberDot-1);$i++){
|
|
|
235 |
|
|
|
236 |
#將黑點前的所有字串合併
|
|
|
237 |
$str = $str.$changedString[$i];
|
| 226 |
liveuser |
238 |
|
| 3 |
liveuser |
239 |
}#for end
|
|
|
240 |
|
|
|
241 |
#如果黑點不等於0個
|
|
|
242 |
if($numberDot!=0){
|
|
|
243 |
|
|
|
244 |
#加上黑點
|
|
|
245 |
$str = $str.".";
|
| 226 |
liveuser |
246 |
|
| 3 |
liveuser |
247 |
#加上副檔名
|
|
|
248 |
$str = $str.$changedString[$numberDot];
|
| 226 |
liveuser |
249 |
|
| 3 |
liveuser |
250 |
#設置執行正常
|
|
|
251 |
$result["status"]="true";
|
| 226 |
liveuser |
252 |
|
| 3 |
liveuser |
253 |
#設置要回傳的字串
|
|
|
254 |
$result["content"]=$str;
|
| 226 |
liveuser |
255 |
|
| 3 |
liveuser |
256 |
#回傳結果
|
|
|
257 |
return $result;
|
| 226 |
liveuser |
258 |
|
| 3 |
liveuser |
259 |
}#if end
|
| 226 |
liveuser |
260 |
|
| 3 |
liveuser |
261 |
#反之,代表沒有副檔名
|
|
|
262 |
else{
|
| 226 |
liveuser |
263 |
|
| 3 |
liveuser |
264 |
#設置執行正常
|
|
|
265 |
$result["status"]="true";
|
| 226 |
liveuser |
266 |
|
| 3 |
liveuser |
267 |
#設置要回傳的字串
|
|
|
268 |
$result["content"]=$conf["stringIn"];
|
| 226 |
liveuser |
269 |
|
| 3 |
liveuser |
270 |
#回傳結果
|
|
|
271 |
return $result;
|
| 226 |
liveuser |
272 |
|
| 3 |
liveuser |
273 |
}#else end
|
| 226 |
liveuser |
274 |
|
| 3 |
liveuser |
275 |
}#function solveDotProblems end
|
|
|
276 |
|
|
|
277 |
/*
|
|
|
278 |
#函式說明:
|
|
|
279 |
#將固定格式的字串開頭移除一個,例如"a,b,c,null"變成"b,c,null"
|
|
|
280 |
#回傳結果:
|
|
|
281 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
282 |
#$result["error"],錯誤訊息陣列
|
|
|
283 |
#$result["function"],當前執行的函數名稱.
|
|
|
284 |
#$result["argu"],使用的參數.
|
|
|
285 |
#$result["dropElement"],被丟棄的元素.
|
|
|
286 |
#必填參數:
|
|
|
287 |
#$conf["stringIn"],字串,要處理的字串。
|
|
|
288 |
$conf["stringIn"]="";
|
|
|
289 |
#可省略參數:
|
|
|
290 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割,預設為",".
|
|
|
291 |
#$conf["spiltSymbol"]="";
|
|
|
292 |
#$conf["unshift"],字串,是否要改成丟棄最後一個元素,預設為"false";反之為"true".
|
|
|
293 |
#$conf["unshift"]="false";
|
|
|
294 |
#參考資料:
|
|
|
295 |
#無.
|
|
|
296 |
#備註:
|
|
|
297 |
#無.
|
|
|
298 |
*/
|
|
|
299 |
public static function stringShift(&$conf){
|
| 226 |
liveuser |
300 |
|
| 3 |
liveuser |
301 |
#檢查參數
|
|
|
302 |
#函式說明:
|
|
|
303 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
304 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
305 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
306 |
#$result["function"],當前執行的函式名稱.
|
|
|
307 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
308 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
309 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
310 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
311 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
312 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
313 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
314 |
#必填寫的參數:
|
|
|
315 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
316 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
317 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
318 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
319 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
320 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
321 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
322 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
323 |
#可以省略的參數:
|
|
|
324 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
325 |
#$conf["canBeEmptyString"]="false";
|
|
|
326 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
327 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("spiltSymbol","unshift");
|
| 226 |
liveuser |
328 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
329 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
330 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
331 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(",","false");
|
|
|
332 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
333 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
334 |
#參考資料來源:
|
|
|
335 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
336 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
337 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
338 |
|
|
|
339 |
#如果檢查有誤
|
|
|
340 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
341 |
|
| 3 |
liveuser |
342 |
#設置錯誤識別
|
|
|
343 |
$result["status"]="false";
|
| 226 |
liveuser |
344 |
|
| 3 |
liveuser |
345 |
#設置錯誤訊息
|
|
|
346 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
347 |
|
| 3 |
liveuser |
348 |
#回傳結果
|
|
|
349 |
return $result;
|
| 226 |
liveuser |
350 |
|
| 3 |
liveuser |
351 |
}#if end
|
| 226 |
liveuser |
352 |
|
| 3 |
liveuser |
353 |
#如果檢查不通過
|
|
|
354 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
355 |
|
| 3 |
liveuser |
356 |
#設置錯誤識別
|
|
|
357 |
$result["status"]="false";
|
| 226 |
liveuser |
358 |
|
| 3 |
liveuser |
359 |
#設置錯誤訊息
|
|
|
360 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
361 |
|
| 3 |
liveuser |
362 |
#回傳結果
|
|
|
363 |
return $result;
|
| 226 |
liveuser |
364 |
|
| 3 |
liveuser |
365 |
}#if end
|
| 226 |
liveuser |
366 |
|
| 3 |
liveuser |
367 |
#函式說明:
|
|
|
368 |
#將特定符號間隔的字串"a,b,c"變成陣列.
|
|
|
369 |
#回傳結果:
|
|
|
370 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
371 |
#$result["function"],當前執行的function名稱.
|
|
|
372 |
#$result["argu"],使用的參數.
|
|
|
373 |
#$result["error"],錯誤訊息陣列.
|
|
|
374 |
#$result["content"],處理好的內容.
|
|
|
375 |
#必填參數:
|
|
|
376 |
#$conf["inputStr"],字串,要轉一維陣列的字串
|
|
|
377 |
$conf["arrays::stringToArray"]["inputStr"]=$conf["stringIn"];
|
|
|
378 |
#可省略參數:
|
|
|
379 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為","
|
|
|
380 |
$conf["arrays::stringToArray"]["spiltSymbol"]=$conf["spiltSymbol"];
|
|
|
381 |
$stringToArray=arrays::stringToArray($conf["arrays::stringToArray"]);
|
|
|
382 |
unset($conf["arrays::stringToArray"]);
|
| 226 |
liveuser |
383 |
|
| 3 |
liveuser |
384 |
#如果轉換失敗
|
|
|
385 |
if($stringToArray["status"]==="false"){
|
| 226 |
liveuser |
386 |
|
| 3 |
liveuser |
387 |
#設置錯誤識別
|
|
|
388 |
$result["status"]="false";
|
| 226 |
liveuser |
389 |
|
| 3 |
liveuser |
390 |
#設置錯誤訊息
|
|
|
391 |
$result["error"]=$stringToArray;
|
| 226 |
liveuser |
392 |
|
| 3 |
liveuser |
393 |
#回傳結果
|
|
|
394 |
return $result;
|
| 226 |
liveuser |
395 |
|
| 3 |
liveuser |
396 |
}#if end
|
| 226 |
liveuser |
397 |
|
| 3 |
liveuser |
398 |
#取得分割好的陣列
|
|
|
399 |
$array=$stringToArray["content"];
|
| 226 |
liveuser |
400 |
|
| 3 |
liveuser |
401 |
#如果沒有要丟棄結尾元素
|
|
|
402 |
if($conf["unshift"]==="false"){
|
| 226 |
liveuser |
403 |
|
| 3 |
liveuser |
404 |
#取得被丟棄的元素
|
|
|
405 |
$result["dropElement"]=array_shift($array);
|
| 226 |
liveuser |
406 |
|
| 3 |
liveuser |
407 |
}#if end
|
| 226 |
liveuser |
408 |
|
| 3 |
liveuser |
409 |
#反之要丟棄開頭元素
|
|
|
410 |
else{
|
| 226 |
liveuser |
411 |
|
| 3 |
liveuser |
412 |
#取得被丟棄的元素,參考資料https://www.php.net/manual/en/function.array-pop.php
|
|
|
413 |
$result["dropElement"]=array_pop($array);
|
| 226 |
liveuser |
414 |
|
| 3 |
liveuser |
415 |
}#else end
|
| 226 |
liveuser |
416 |
|
| 3 |
liveuser |
417 |
#函式說明:
|
|
|
418 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
419 |
#回傳結果:
|
|
|
420 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
421 |
#$result["function"],當前執行的function名稱
|
|
|
422 |
#$result["error"],錯誤訊息陣列.
|
|
|
423 |
#$result["content"],處理好的字串.
|
|
|
424 |
#$result["argu"],使用的參數.
|
|
|
425 |
#必填參數:
|
|
|
426 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
427 |
$conf["arrays::arrayToString"]["inputArray"]=$array;
|
|
|
428 |
#可省略參數:
|
|
|
429 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
430 |
$conf["arrays::arrayToString"]["spiltSymbol"]=$conf["spiltSymbol"];
|
|
|
431 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
432 |
$conf["arrays::arrayToString"]["skipEnd"]="true";
|
|
|
433 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
434 |
unset($conf["arrays::arrayToString"]);
|
| 226 |
liveuser |
435 |
|
| 3 |
liveuser |
436 |
#如果轉換失敗
|
|
|
437 |
if($arrayToString["status"]==="false"){
|
| 226 |
liveuser |
438 |
|
| 3 |
liveuser |
439 |
#設置錯誤識別
|
|
|
440 |
$result["status"]="false";
|
| 226 |
liveuser |
441 |
|
| 3 |
liveuser |
442 |
#設置錯誤訊息
|
|
|
443 |
$result["error"]=$arrayToString;
|
| 226 |
liveuser |
444 |
|
| 3 |
liveuser |
445 |
#回傳結果
|
|
|
446 |
return $result;
|
| 226 |
liveuser |
447 |
|
| 3 |
liveuser |
448 |
}#if end
|
| 226 |
liveuser |
449 |
|
| 3 |
liveuser |
450 |
#取得處理好的字串
|
|
|
451 |
$result["content"]=$arrayToString["content"];
|
| 226 |
liveuser |
452 |
|
| 3 |
liveuser |
453 |
#設置執行正常
|
|
|
454 |
$result["status"]="true";
|
| 226 |
liveuser |
455 |
|
| 3 |
liveuser |
456 |
#回傳結果
|
|
|
457 |
return $result;
|
| 226 |
liveuser |
458 |
|
| 3 |
liveuser |
459 |
}#function stringShift end
|
|
|
460 |
|
|
|
461 |
/*
|
|
|
462 |
#函式說明:
|
|
|
463 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
464 |
#回傳結果:
|
|
|
465 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
466 |
#$result["error"],錯誤訊息陣列
|
|
|
467 |
#$result["function"],當前執行的函數名稱.
|
|
|
468 |
#$result["argu"],使用的參數.
|
|
|
469 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
470 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
471 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
472 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
473 |
#必填參數:
|
|
|
474 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
475 |
$conf["stringIn"]="";
|
|
|
476 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
477 |
$conf["spiltSymbol"]="";
|
|
|
478 |
#可省略參數:
|
|
|
479 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
480 |
#$conf["allowEmptyStr"]="false";
|
|
|
481 |
#參考資料:
|
|
|
482 |
#無.
|
|
|
483 |
#備註:
|
|
|
484 |
#無.
|
|
|
485 |
*/
|
|
|
486 |
public static function spiltString(&$conf){
|
|
|
487 |
|
|
|
488 |
#初始化要回傳的內容
|
|
|
489 |
$result=array();
|
|
|
490 |
|
|
|
491 |
#取得當前執行的函數名稱
|
|
|
492 |
$result["function"]=__FUNCTION__;
|
|
|
493 |
|
|
|
494 |
#如果 $conf 不為陣列
|
|
|
495 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
496 |
|
| 3 |
liveuser |
497 |
#設置執行失敗
|
|
|
498 |
$result["status"]="false";
|
| 226 |
liveuser |
499 |
|
| 3 |
liveuser |
500 |
#設置執行錯誤訊息
|
|
|
501 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
502 |
|
|
|
503 |
#如果傳入的參數為 null
|
|
|
504 |
if($conf==null){
|
| 226 |
liveuser |
505 |
|
| 3 |
liveuser |
506 |
#設置執行錯誤訊息
|
|
|
507 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
508 |
|
| 3 |
liveuser |
509 |
}#if end
|
|
|
510 |
|
|
|
511 |
#回傳結果
|
|
|
512 |
return $result;
|
| 226 |
liveuser |
513 |
|
| 3 |
liveuser |
514 |
}#if end
|
|
|
515 |
|
|
|
516 |
#記錄使用的參數
|
|
|
517 |
$result["argu"]=$conf;
|
|
|
518 |
|
|
|
519 |
#檢查參數
|
|
|
520 |
#函式說明:
|
|
|
521 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
522 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
523 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
524 |
#$result["function"],當前執行的函式名稱.
|
|
|
525 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
526 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
527 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
528 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
529 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
530 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
531 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
532 |
#必填寫的參數:
|
|
|
533 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
534 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
535 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
536 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","spiltSymbol");
|
| 226 |
liveuser |
537 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
538 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
539 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
540 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
541 |
#可以省略的參數:
|
|
|
542 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
543 |
#$conf["canBeEmptyString"]="false";
|
|
|
544 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
545 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("allowEmptyStr");
|
| 226 |
liveuser |
546 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
547 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
548 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
549 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
550 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
551 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
552 |
#參考資料來源:
|
|
|
553 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
554 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
555 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
556 |
|
|
|
557 |
#如果檢查有誤
|
|
|
558 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
559 |
|
| 3 |
liveuser |
560 |
#設置錯誤識別
|
|
|
561 |
$result["status"]="false";
|
| 226 |
liveuser |
562 |
|
| 3 |
liveuser |
563 |
#設置錯誤訊息
|
|
|
564 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
565 |
|
| 3 |
liveuser |
566 |
#回傳結果
|
|
|
567 |
return $result;
|
| 226 |
liveuser |
568 |
|
| 3 |
liveuser |
569 |
}#if end
|
| 226 |
liveuser |
570 |
|
| 3 |
liveuser |
571 |
#如果檢查不通過
|
|
|
572 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
573 |
|
| 3 |
liveuser |
574 |
#設置錯誤識別
|
|
|
575 |
$result["status"]="false";
|
| 226 |
liveuser |
576 |
|
| 3 |
liveuser |
577 |
#設置錯誤訊息
|
|
|
578 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
579 |
|
| 3 |
liveuser |
580 |
#回傳結果
|
|
|
581 |
return $result;
|
| 226 |
liveuser |
582 |
|
| 3 |
liveuser |
583 |
}#if end
|
| 226 |
liveuser |
584 |
|
| 3 |
liveuser |
585 |
#取得 $conf["stringIn"] 的 unicode 長度
|
|
|
586 |
$stringInLength=mb_strlen($conf["stringIn"],"UTF-8");
|
| 226 |
liveuser |
587 |
|
| 3 |
liveuser |
588 |
#取得 $conf["spiltSymbol"] 的 unicode 長度
|
|
|
589 |
$spiltSymbolLength=mb_strlen($conf["spiltSymbol"],"UTF-8");
|
| 226 |
liveuser |
590 |
|
| 3 |
liveuser |
591 |
#置換$conf["stringIn"]成unicode字串
|
|
|
592 |
$conf["stringIn"]=mb_substr($conf["stringIn"],0,$stringInLength,"UTF-8");
|
| 226 |
liveuser |
593 |
|
| 3 |
liveuser |
594 |
#置換$conf["spiltSymbol"]成unicode字串
|
| 226 |
liveuser |
595 |
$conf["spiltSymbol"]=mb_substr($conf["spiltSymbol"],0,$spiltSymbolLength,"UTF-8");
|
| 3 |
liveuser |
596 |
|
|
|
597 |
#var_dump($conf["spiltSymbol"]);
|
|
|
598 |
|
|
|
599 |
#取得該字串有幾個 $conf["spiltSymbol"]
|
| 226 |
liveuser |
600 |
$numberSymbol=substr_count($conf["stringIn"],$conf["spiltSymbol"]);
|
| 3 |
liveuser |
601 |
|
|
|
602 |
#如果裡面有分割用的符號
|
|
|
603 |
if($numberSymbol!==0){
|
|
|
604 |
|
|
|
605 |
#設置沒有找到分割用的關鍵字
|
|
|
606 |
$result["found"]="true";
|
|
|
607 |
|
|
|
608 |
#依據 $spiltSymbol 分割,並將陣列變數存到 $result["dataArray"]
|
| 226 |
liveuser |
609 |
$result["dataArray"]=explode($conf["spiltSymbol"],$conf["stringIn"]);
|
| 3 |
liveuser |
610 |
|
|
|
611 |
#如果分割出來的結果是空的
|
|
|
612 |
if(count($result["dataArray"])==0){
|
| 226 |
liveuser |
613 |
|
| 3 |
liveuser |
614 |
#取得總共有多少段
|
|
|
615 |
$result["dataCounts"]=0;
|
| 226 |
liveuser |
616 |
|
| 3 |
liveuser |
617 |
}#if end
|
| 226 |
liveuser |
618 |
|
|
|
619 |
#反之分割出來不是空的
|
| 3 |
liveuser |
620 |
else{
|
|
|
621 |
|
|
|
622 |
#如果存在最後一個選項
|
|
|
623 |
if(isset($result["dataArray"][count($result["dataArray"])-1])){
|
|
|
624 |
|
|
|
625 |
#如果最後一個選項為空
|
|
|
626 |
if($result["dataArray"][count($result["dataArray"])-1]==""){
|
| 226 |
liveuser |
627 |
|
| 3 |
liveuser |
628 |
#卸除該元素
|
|
|
629 |
unset($result["dataArray"][count($result["dataArray"])-1]);
|
| 226 |
liveuser |
630 |
|
| 3 |
liveuser |
631 |
}#if end
|
| 226 |
liveuser |
632 |
|
| 3 |
liveuser |
633 |
}#if end
|
| 226 |
liveuser |
634 |
|
| 3 |
liveuser |
635 |
#取得總共有多少段
|
|
|
636 |
$result["dataCounts"]=count($result["dataArray"]);
|
| 226 |
liveuser |
637 |
|
| 3 |
liveuser |
638 |
}#else end
|
|
|
639 |
|
|
|
640 |
#取得原始要分割的字串
|
|
|
641 |
$result["oriStr"]=$conf["stringIn"];
|
|
|
642 |
|
|
|
643 |
}#if end
|
| 226 |
liveuser |
644 |
|
| 3 |
liveuser |
645 |
#反之
|
|
|
646 |
else{
|
| 226 |
liveuser |
647 |
|
| 3 |
liveuser |
648 |
#設置只有一個片段
|
|
|
649 |
$result["dataCounts"]=1;
|
| 226 |
liveuser |
650 |
|
| 3 |
liveuser |
651 |
#取得第一個片段亦即原始字串的內容
|
|
|
652 |
$result["dataArray"][0]=$conf["stringIn"];
|
|
|
653 |
|
|
|
654 |
#取得原始要分割的字串
|
|
|
655 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
656 |
|
| 3 |
liveuser |
657 |
#設置沒有找到分割用的關鍵字
|
|
|
658 |
$result["found"]="false";
|
| 226 |
liveuser |
659 |
|
| 3 |
liveuser |
660 |
}#else end
|
| 226 |
liveuser |
661 |
|
|
|
662 |
#如果不允許分割出空字串
|
| 3 |
liveuser |
663 |
if($conf["allowEmptyStr"]=="false"){
|
| 226 |
liveuser |
664 |
|
| 3 |
liveuser |
665 |
#依據 $result["dataCounts"] 檢查分割好的片段內容是否有含有 "" 的內容
|
|
|
666 |
for($i=0;$i<$result["dataCounts"];$i++){
|
| 226 |
liveuser |
667 |
|
| 3 |
liveuser |
668 |
#如果 分割好的片段內容含有 "" 的內容
|
|
|
669 |
if($result["dataArray"][$i]==""){
|
| 226 |
liveuser |
670 |
|
| 3 |
liveuser |
671 |
#卸除其變數內容
|
|
|
672 |
unset($result["dataArray"][$i]);
|
| 226 |
liveuser |
673 |
|
| 3 |
liveuser |
674 |
}#if end
|
| 226 |
liveuser |
675 |
|
| 3 |
liveuser |
676 |
}#for end
|
| 226 |
liveuser |
677 |
|
| 3 |
liveuser |
678 |
#重新計數目前分割成幾段內容
|
|
|
679 |
$result["dataCounts"]=count($result["dataArray"]);
|
| 226 |
liveuser |
680 |
|
| 3 |
liveuser |
681 |
#初始化計數當前要儲存的片段其key爲何
|
|
|
682 |
$cilpKey=0;
|
| 226 |
liveuser |
683 |
|
| 3 |
liveuser |
684 |
#重新排序分割好片段的k
|
|
|
685 |
foreach($result["dataArray"] as $cilpOriKey => $clipValue){
|
| 226 |
liveuser |
686 |
|
| 3 |
liveuser |
687 |
#卸除原始元素所屬key的變數
|
|
|
688 |
unset($result["dataArray"][$cilpOriKey]);
|
| 226 |
liveuser |
689 |
|
| 3 |
liveuser |
690 |
#取得片段的內容,並指派key
|
|
|
691 |
$result["dataArray"][$cilpKey]=$clipValue;
|
| 226 |
liveuser |
692 |
|
| 3 |
liveuser |
693 |
#計數當前要儲存片段的key+1
|
|
|
694 |
$cilpKey++;
|
| 226 |
liveuser |
695 |
|
| 3 |
liveuser |
696 |
}#foreache end
|
| 226 |
liveuser |
697 |
|
| 3 |
liveuser |
698 |
}#if end
|
| 226 |
liveuser |
699 |
|
| 3 |
liveuser |
700 |
#執行到這邊代表執行正常
|
|
|
701 |
$result["status"]="true";
|
| 226 |
liveuser |
702 |
|
| 3 |
liveuser |
703 |
#回傳結果
|
|
|
704 |
return $result;
|
|
|
705 |
|
|
|
706 |
}#funcion spiltString end
|
| 226 |
liveuser |
707 |
|
| 33 |
liveuser |
708 |
/*
|
|
|
709 |
#函式說明:
|
|
|
710 |
#將mutf7的字串轉成uft8
|
|
|
711 |
#回傳結果:
|
|
|
712 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
713 |
#$result["error"],錯誤訊息陣列.
|
|
|
714 |
#$result["function"],當前執行的函數名稱.
|
|
|
715 |
#$result["content"],轉好的字串.
|
|
|
716 |
#必填參數:
|
|
|
717 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
718 |
$conf["stringIn"]="";
|
|
|
719 |
#可省略參數:
|
|
|
720 |
#無.
|
|
|
721 |
#參考資料:
|
|
|
722 |
#https://www.php.net/manual/en/function.mb-convert-encoding.php
|
|
|
723 |
#https://www.php.net/manual/en/mbstring.supported-encodings.php
|
|
|
724 |
#備註:
|
|
|
725 |
#無.
|
|
|
726 |
*/
|
|
|
727 |
public static function utf7_imap_to_utf8($conf){
|
| 226 |
liveuser |
728 |
|
| 33 |
liveuser |
729 |
#初始化要回傳的內容
|
|
|
730 |
$result=array();
|
|
|
731 |
|
|
|
732 |
#取得當前執行的函數名稱
|
|
|
733 |
$result["function"]=__FUNCTION__;
|
|
|
734 |
|
|
|
735 |
#如果 $conf 不為陣列
|
|
|
736 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
737 |
|
| 33 |
liveuser |
738 |
#設置執行失敗
|
|
|
739 |
$result["status"]="false";
|
| 226 |
liveuser |
740 |
|
| 33 |
liveuser |
741 |
#設置執行錯誤訊息
|
|
|
742 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
743 |
|
|
|
744 |
#如果傳入的參數為 null
|
|
|
745 |
if($conf==null){
|
| 226 |
liveuser |
746 |
|
| 33 |
liveuser |
747 |
#設置執行錯誤訊息
|
|
|
748 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
749 |
|
| 33 |
liveuser |
750 |
}#if end
|
|
|
751 |
|
|
|
752 |
#回傳結果
|
|
|
753 |
return $result;
|
| 226 |
liveuser |
754 |
|
| 33 |
liveuser |
755 |
}#if end
|
|
|
756 |
|
|
|
757 |
#檢查參數
|
|
|
758 |
#函式說明:
|
|
|
759 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
760 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
761 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
762 |
#$result["function"],當前執行的函式名稱.
|
|
|
763 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
764 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
765 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
766 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
767 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
768 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
769 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
770 |
#必填寫的參數:
|
|
|
771 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
772 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
773 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
774 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
775 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 33 |
liveuser |
776 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
777 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
778 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
779 |
#可以省略的參數:
|
|
|
780 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
781 |
#$conf["canBeEmptyString"]="false";
|
|
|
782 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
783 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
784 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 33 |
liveuser |
785 |
#$conf["skipableVariableType"]=array();
|
|
|
786 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
787 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
788 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
789 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
790 |
#參考資料來源:
|
|
|
791 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
792 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
793 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
794 |
|
|
|
795 |
#如果檢查有誤
|
|
|
796 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
797 |
|
| 33 |
liveuser |
798 |
#設置錯誤識別
|
|
|
799 |
$result["status"]="false";
|
| 226 |
liveuser |
800 |
|
| 33 |
liveuser |
801 |
#設置錯誤訊息
|
|
|
802 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
803 |
|
| 33 |
liveuser |
804 |
#回傳結果
|
|
|
805 |
return $result;
|
| 226 |
liveuser |
806 |
|
| 33 |
liveuser |
807 |
}#if end
|
| 226 |
liveuser |
808 |
|
| 33 |
liveuser |
809 |
#如果檢查不通過
|
|
|
810 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
811 |
|
| 33 |
liveuser |
812 |
#設置錯誤識別
|
|
|
813 |
$result["status"]="false";
|
| 226 |
liveuser |
814 |
|
| 33 |
liveuser |
815 |
#設置錯誤訊息
|
|
|
816 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
817 |
|
| 33 |
liveuser |
818 |
#回傳結果
|
|
|
819 |
return $result;
|
| 226 |
liveuser |
820 |
|
| 33 |
liveuser |
821 |
}#if end
|
| 226 |
liveuser |
822 |
|
| 33 |
liveuser |
823 |
#取得轉好編碼的內容
|
|
|
824 |
$result["content"]=mb_convert_encoding($conf["stringIn"],"UTF8","UTF7-IMAP");
|
| 226 |
liveuser |
825 |
|
| 33 |
liveuser |
826 |
#設置執行正常
|
|
|
827 |
$result["status"]="true";
|
| 226 |
liveuser |
828 |
|
| 33 |
liveuser |
829 |
#回傳結果
|
|
|
830 |
return $result;
|
| 226 |
liveuser |
831 |
|
| 33 |
liveuser |
832 |
}#function utf7_imap_to_utf8 end
|
| 226 |
liveuser |
833 |
|
| 3 |
liveuser |
834 |
/*
|
|
|
835 |
#函式說明:
|
|
|
836 |
#將多個固定格式的字串分開,並回傳分開的結果
|
|
|
837 |
#回傳結果:
|
|
|
838 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
839 |
#$result["error"],錯誤訊息陣列.
|
|
|
840 |
#$result["function"],當前執行的函數名稱.
|
|
|
841 |
#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
|
|
|
842 |
#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
|
|
|
843 |
#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
|
|
|
844 |
#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
|
|
|
845 |
#必填參數:
|
|
|
846 |
#$conf["stringIn"],字串陣列,要處理的字串陣列.
|
|
|
847 |
$conf["stringIn"]=array();
|
|
|
848 |
#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
|
|
|
849 |
$conf["spiltSymbol"]="";
|
|
|
850 |
#可省略參數:
|
|
|
851 |
#無.
|
|
|
852 |
#參考資料:
|
|
|
853 |
#無.
|
|
|
854 |
#備註:
|
|
|
855 |
#無.
|
|
|
856 |
*/
|
|
|
857 |
public static function spiltMutiString(&$conf){
|
|
|
858 |
|
|
|
859 |
#初始化要回傳的內容
|
|
|
860 |
$result=array();
|
|
|
861 |
|
|
|
862 |
#取得當前執行的函數名稱
|
|
|
863 |
$result["function"]=__FUNCTION__;
|
|
|
864 |
|
|
|
865 |
#如果 $conf 不為陣列
|
|
|
866 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
867 |
|
| 3 |
liveuser |
868 |
#設置執行失敗
|
|
|
869 |
$result["status"]="false";
|
| 226 |
liveuser |
870 |
|
| 3 |
liveuser |
871 |
#設置執行錯誤訊息
|
|
|
872 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
873 |
|
|
|
874 |
#如果傳入的參數為 null
|
|
|
875 |
if($conf==null){
|
| 226 |
liveuser |
876 |
|
| 3 |
liveuser |
877 |
#設置執行錯誤訊息
|
|
|
878 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
879 |
|
| 3 |
liveuser |
880 |
}#if end
|
|
|
881 |
|
|
|
882 |
#回傳結果
|
|
|
883 |
return $result;
|
| 226 |
liveuser |
884 |
|
| 3 |
liveuser |
885 |
}#if end
|
|
|
886 |
|
|
|
887 |
#檢查參數
|
|
|
888 |
#函式說明:
|
|
|
889 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
890 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
891 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
892 |
#$result["function"],當前執行的函式名稱.
|
|
|
893 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
894 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
895 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
896 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
897 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
898 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
899 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
900 |
#必填寫的參數:
|
|
|
901 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
902 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
903 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
904 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","spiltSymbol");
|
| 226 |
liveuser |
905 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
906 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
907 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
908 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
909 |
#可以省略的參數:
|
|
|
910 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
911 |
#$conf["canBeEmptyString"]="false";
|
|
|
912 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
913 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
914 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
915 |
#$conf["skipableVariableType"]=array();
|
|
|
916 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
917 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
918 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
919 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
920 |
#參考資料來源:
|
|
|
921 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
922 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
923 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
924 |
|
|
|
925 |
#如果檢查有誤
|
|
|
926 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
927 |
|
| 3 |
liveuser |
928 |
#設置錯誤識別
|
|
|
929 |
$result["status"]="false";
|
| 226 |
liveuser |
930 |
|
| 3 |
liveuser |
931 |
#設置錯誤訊息
|
|
|
932 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
933 |
|
| 3 |
liveuser |
934 |
#回傳結果
|
|
|
935 |
return $result;
|
| 226 |
liveuser |
936 |
|
| 3 |
liveuser |
937 |
}#if end
|
| 226 |
liveuser |
938 |
|
| 3 |
liveuser |
939 |
#如果檢查不通過
|
|
|
940 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
941 |
|
| 3 |
liveuser |
942 |
#設置錯誤識別
|
|
|
943 |
$result["status"]="false";
|
| 226 |
liveuser |
944 |
|
| 3 |
liveuser |
945 |
#設置錯誤訊息
|
|
|
946 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
947 |
|
| 3 |
liveuser |
948 |
#回傳結果
|
|
|
949 |
return $result;
|
| 226 |
liveuser |
950 |
|
| 3 |
liveuser |
951 |
}#if end
|
| 226 |
liveuser |
952 |
|
| 3 |
liveuser |
953 |
#初始化 $result_spiltString
|
|
|
954 |
$result_spiltString=array();
|
|
|
955 |
|
|
|
956 |
#根據有幾個字串要進行切割,就執行幾次
|
|
|
957 |
#for($i=0;$i<count($conf["stringIn"]);$i++){
|
|
|
958 |
foreach($conf["stringIn"] as $key=>$value){
|
|
|
959 |
|
|
|
960 |
#debug
|
|
|
961 |
#var_dump($conf["stringIn"]);
|
|
|
962 |
|
|
|
963 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
964 |
#回傳的參數:
|
|
|
965 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
966 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
967 |
#必填參數:
|
|
|
968 |
$conf_spiltString["stringIn"]=$value;#要處理的字串。
|
|
|
969 |
$conf_spiltString["spiltSymbol"]=$conf["spiltSymbol"];#爲以哪個符號作爲分割
|
|
|
970 |
$spiltString=stringProcess::spiltString($conf_spiltString);
|
|
|
971 |
unset($conf_spiltString);
|
| 226 |
liveuser |
972 |
|
| 3 |
liveuser |
973 |
#如果分開字串失敗
|
|
|
974 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
975 |
|
| 3 |
liveuser |
976 |
#設置錯誤識別
|
|
|
977 |
$result["status"]="false";
|
| 226 |
liveuser |
978 |
|
| 3 |
liveuser |
979 |
#設置錯誤訊息
|
|
|
980 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
981 |
|
| 3 |
liveuser |
982 |
#回傳結果
|
|
|
983 |
return $result;
|
| 226 |
liveuser |
984 |
|
| 3 |
liveuser |
985 |
}#if end
|
| 226 |
liveuser |
986 |
|
| 3 |
liveuser |
987 |
#取得分割字串後的結果
|
|
|
988 |
$result_spiltString[]=$spiltString;
|
|
|
989 |
|
|
|
990 |
}#for end
|
| 226 |
liveuser |
991 |
|
| 3 |
liveuser |
992 |
#取得所有字串分割的結果
|
|
|
993 |
$result["spiltString"]=$result_spiltString;
|
|
|
994 |
|
|
|
995 |
#通過以上檢測,將執行狀態結果設爲 "true"
|
|
|
996 |
$result["status"]="true";
|
|
|
997 |
|
|
|
998 |
#回傳結果
|
|
|
999 |
return $result;
|
| 226 |
liveuser |
1000 |
|
| 3 |
liveuser |
1001 |
}#function spiltMutiString end
|
|
|
1002 |
|
|
|
1003 |
/*
|
|
|
1004 |
#函式說明:
|
|
|
1005 |
#將多行內容的字串,依行切割,切割的依據為"\r\n".
|
|
|
1006 |
#回傳結果:
|
|
|
1007 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗.
|
|
|
1008 |
#$result["error"],錯誤訊息陣列.
|
|
|
1009 |
#$result["function"],當前執行的函數名稱.#$result["oriStr"],要分割的原始字串內容.
|
|
|
1010 |
#$result["oriStr"],要分割的原始字串內容.
|
|
|
1011 |
#$result["dataArray"],爲以行分割好的字串陣列內容,$result["dataArray"][$i]爲第($i+1)行的內容.
|
|
|
1012 |
#$result["dataCounts"],爲總共分成幾行.
|
|
|
1013 |
#必填參數:
|
|
|
1014 |
#$conf["stringIn"],字串,要處理的多行文字字串.
|
|
|
1015 |
$conf["stringIn"]="";
|
|
|
1016 |
#可省略參數:
|
|
|
1017 |
#無.
|
|
|
1018 |
#參考資料:
|
|
|
1019 |
#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 換行字元
|
|
|
1020 |
#備註:
|
|
|
1021 |
#無.
|
|
|
1022 |
*/
|
|
|
1023 |
public static function spiltMutiLineString(&$conf){
|
| 226 |
liveuser |
1024 |
|
| 3 |
liveuser |
1025 |
#初始化要回傳的內容
|
|
|
1026 |
$result=array();
|
|
|
1027 |
|
|
|
1028 |
#取得當前執行的函數名稱
|
|
|
1029 |
$result["function"]=__FUNCTION__;
|
|
|
1030 |
|
|
|
1031 |
#如果 $conf 不為陣列
|
|
|
1032 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1033 |
|
| 3 |
liveuser |
1034 |
#設置執行失敗
|
|
|
1035 |
$result["status"]="false";
|
| 226 |
liveuser |
1036 |
|
| 3 |
liveuser |
1037 |
#設置執行錯誤訊息
|
|
|
1038 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1039 |
|
|
|
1040 |
#如果傳入的參數為 null
|
|
|
1041 |
if($conf==null){
|
| 226 |
liveuser |
1042 |
|
| 3 |
liveuser |
1043 |
#設置執行錯誤訊息
|
|
|
1044 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1045 |
|
| 3 |
liveuser |
1046 |
}#if end
|
|
|
1047 |
|
|
|
1048 |
#回傳結果
|
|
|
1049 |
return $result;
|
| 226 |
liveuser |
1050 |
|
| 3 |
liveuser |
1051 |
}#if end
|
|
|
1052 |
|
|
|
1053 |
#檢查參數
|
|
|
1054 |
#函式說明:
|
|
|
1055 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1056 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1057 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1058 |
#$result["function"],當前執行的函式名稱.
|
|
|
1059 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1060 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1061 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1062 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1063 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1064 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1065 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1066 |
#必填寫的參數:
|
|
|
1067 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1068 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1069 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1070 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1071 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1072 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1073 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1074 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1075 |
#可以省略的參數:
|
|
|
1076 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1077 |
#$conf["canBeEmptyString"]="false";
|
|
|
1078 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1079 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
1080 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1081 |
#$conf["skipableVariableType"]=array();
|
|
|
1082 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1083 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1084 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1085 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1086 |
#參考資料來源:
|
|
|
1087 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1088 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1089 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1090 |
|
|
|
1091 |
#如果檢查有誤
|
|
|
1092 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1093 |
|
| 3 |
liveuser |
1094 |
#設置錯誤識別
|
|
|
1095 |
$result["status"]="false";
|
| 226 |
liveuser |
1096 |
|
| 3 |
liveuser |
1097 |
#設置錯誤訊息
|
|
|
1098 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1099 |
|
| 3 |
liveuser |
1100 |
#回傳結果
|
|
|
1101 |
return $result;
|
| 226 |
liveuser |
1102 |
|
| 3 |
liveuser |
1103 |
}#if end
|
| 226 |
liveuser |
1104 |
|
| 3 |
liveuser |
1105 |
#如果檢查不通過
|
|
|
1106 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1107 |
|
| 3 |
liveuser |
1108 |
#設置錯誤識別
|
|
|
1109 |
$result["status"]="false";
|
| 226 |
liveuser |
1110 |
|
| 3 |
liveuser |
1111 |
#設置錯誤訊息
|
|
|
1112 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1113 |
|
| 3 |
liveuser |
1114 |
#回傳結果
|
|
|
1115 |
return $result;
|
| 226 |
liveuser |
1116 |
|
| 3 |
liveuser |
1117 |
}#if end
|
| 226 |
liveuser |
1118 |
|
| 3 |
liveuser |
1119 |
#儲存要分割的原始字串內容
|
|
|
1120 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
1121 |
|
| 3 |
liveuser |
1122 |
#檢查多行文字是用\r\n還是\n來換行
|
|
|
1123 |
#函式說明:
|
|
|
1124 |
#檢查字串裡面有無指定的關鍵字
|
|
|
1125 |
#回傳結果:
|
|
|
1126 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1127 |
#$result["error"],錯誤訊息
|
|
|
1128 |
#$result["function"],當前執行的函數名稱.
|
|
|
1129 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
1130 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
1131 |
#必填參數:
|
|
|
1132 |
$conf["search::findKeyWord"]["keyWord"]="\r\n";#想要搜尋的關鍵字
|
|
|
1133 |
$conf["search::findKeyWord"]["string"]=$conf["stringIn"];#要被搜尋的字串內容
|
|
|
1134 |
#可省略參數:
|
|
|
1135 |
$conf["search::findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
1136 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
1137 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
1138 |
|
| 3 |
liveuser |
1139 |
#如果檢查出錯
|
|
|
1140 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
1141 |
|
| 3 |
liveuser |
1142 |
#設置錯誤識別
|
|
|
1143 |
$result["status"]="false";
|
| 226 |
liveuser |
1144 |
|
| 3 |
liveuser |
1145 |
#設置錯誤訊息
|
|
|
1146 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
1147 |
|
| 3 |
liveuser |
1148 |
#回傳結果
|
|
|
1149 |
return $result;
|
| 226 |
liveuser |
1150 |
|
| 3 |
liveuser |
1151 |
}#if end
|
| 226 |
liveuser |
1152 |
|
| 3 |
liveuser |
1153 |
#預設換行的符號
|
|
|
1154 |
$spiltSymbol="\n";
|
| 226 |
liveuser |
1155 |
|
| 3 |
liveuser |
1156 |
#如果有找到關鍵字
|
|
|
1157 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
1158 |
|
| 3 |
liveuser |
1159 |
#更換換行的符號
|
|
|
1160 |
$spiltSymbol="\r\n";
|
| 226 |
liveuser |
1161 |
|
| 3 |
liveuser |
1162 |
}#if end
|
| 226 |
liveuser |
1163 |
|
| 3 |
liveuser |
1164 |
#函式說明:
|
|
|
1165 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1166 |
#回傳的參數:
|
|
|
1167 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1168 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1169 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1170 |
#必填參數:
|
|
|
1171 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$conf["stringIn"];#要處理的字串。
|
|
|
1172 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=$spiltSymbol;#爲以哪個符號作爲分割
|
|
|
1173 |
$spiltString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
1174 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
1175 |
|
| 3 |
liveuser |
1176 |
#如果分割字串失敗
|
|
|
1177 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
1178 |
|
| 3 |
liveuser |
1179 |
#設置錯誤識別
|
|
|
1180 |
$result["status"]="false";
|
| 226 |
liveuser |
1181 |
|
| 3 |
liveuser |
1182 |
#設置錯誤訊息
|
|
|
1183 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1184 |
|
| 3 |
liveuser |
1185 |
#回傳結果
|
|
|
1186 |
return $result;
|
| 226 |
liveuser |
1187 |
|
| 3 |
liveuser |
1188 |
}#if end
|
| 226 |
liveuser |
1189 |
|
| 3 |
liveuser |
1190 |
#儲存每一行的內容
|
|
|
1191 |
$result["dataArray"]=$spiltString["dataArray"];
|
| 226 |
liveuser |
1192 |
|
| 3 |
liveuser |
1193 |
#取得分成幾行
|
|
|
1194 |
$result["dataCounts"]=$spiltString["dataCounts"];
|
| 226 |
liveuser |
1195 |
|
| 3 |
liveuser |
1196 |
#執行到這邊,代表執行成功
|
|
|
1197 |
$result["status"]="true";
|
| 226 |
liveuser |
1198 |
|
| 3 |
liveuser |
1199 |
#回傳每行的內容
|
|
|
1200 |
return $result;
|
| 226 |
liveuser |
1201 |
|
| 3 |
liveuser |
1202 |
}#funcrion spiltMutiLineString end
|
|
|
1203 |
|
|
|
1204 |
/*
|
|
|
1205 |
#函式說明:
|
|
|
1206 |
#將一字串的前幾個文字轉爲ACSII並存到陣列裏面
|
|
|
1207 |
#回傳結果:
|
|
|
1208 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
1209 |
#$result["error"],錯誤訊息陣列.
|
|
|
1210 |
#$result["function"],當前執行的函數名稱.
|
|
|
1211 |
#$result["dataCounts"],爲總共有幾個字轉好的ASCII陣列。
|
|
|
1212 |
#$result["acsiiArray"],爲每個字轉好的ASCII陣列內容,$result["acsiiArray"][$i]爲第 $i+1 個字的ACSII內容。
|
|
|
1213 |
#必填參數:
|
|
|
1214 |
#$conf["stringIn"],字串,爲要處理的字串.
|
|
|
1215 |
$conf["stringIn"]="";
|
|
|
1216 |
#可省略參數:
|
|
|
1217 |
#$conf["wordsLong"],字串,爲要取得前幾個字元,若沒有要限定則可以不設定內容。
|
|
|
1218 |
#$conf["wordsLong"]="";
|
|
|
1219 |
#參考資料:
|
|
|
1220 |
#無.
|
|
|
1221 |
#備註:
|
|
|
1222 |
#無.
|
| 226 |
liveuser |
1223 |
*/
|
| 3 |
liveuser |
1224 |
function StringToASCII(&$conf){
|
|
|
1225 |
|
|
|
1226 |
#初始化要回傳的內容
|
|
|
1227 |
$result=array();
|
|
|
1228 |
|
|
|
1229 |
#取得當前執行的函數名稱
|
|
|
1230 |
$result["function"]=__FUNCTION__;
|
|
|
1231 |
|
|
|
1232 |
#如果 $conf 不為陣列
|
|
|
1233 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1234 |
|
| 3 |
liveuser |
1235 |
#設置執行失敗
|
|
|
1236 |
$result["status"]="false";
|
| 226 |
liveuser |
1237 |
|
| 3 |
liveuser |
1238 |
#設置執行錯誤訊息
|
|
|
1239 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1240 |
|
|
|
1241 |
#回傳結果
|
|
|
1242 |
return $result;
|
| 226 |
liveuser |
1243 |
|
| 3 |
liveuser |
1244 |
}#if end
|
|
|
1245 |
|
|
|
1246 |
#檢查參數
|
|
|
1247 |
#函式說明:
|
|
|
1248 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1249 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1250 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1251 |
#$result["function"],當前執行的函式名稱.
|
|
|
1252 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1253 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1254 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1255 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1256 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1257 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1258 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1259 |
#必填寫的參數:
|
|
|
1260 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1261 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1262 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1263 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1264 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1265 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1266 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1267 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1268 |
#可以省略的參數:
|
|
|
1269 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1270 |
#$conf["canBeEmptyString"]="false";
|
|
|
1271 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1272 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wordsLong");
|
| 226 |
liveuser |
1273 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1274 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
1275 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1276 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
1277 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1278 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1279 |
#參考資料來源:
|
|
|
1280 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1281 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1282 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1283 |
|
|
|
1284 |
#如果檢查有誤
|
|
|
1285 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1286 |
|
| 3 |
liveuser |
1287 |
#設置錯誤識別
|
|
|
1288 |
$result["status"]="false";
|
| 226 |
liveuser |
1289 |
|
| 3 |
liveuser |
1290 |
#設置錯誤訊息
|
|
|
1291 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1292 |
|
| 3 |
liveuser |
1293 |
#回傳結果
|
|
|
1294 |
return $result;
|
| 226 |
liveuser |
1295 |
|
| 3 |
liveuser |
1296 |
}#if end
|
| 226 |
liveuser |
1297 |
|
| 3 |
liveuser |
1298 |
#如果檢查不通過
|
|
|
1299 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1300 |
|
| 3 |
liveuser |
1301 |
#設置錯誤識別
|
|
|
1302 |
$result["status"]="false";
|
| 226 |
liveuser |
1303 |
|
| 3 |
liveuser |
1304 |
#設置錯誤訊息
|
|
|
1305 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1306 |
|
| 3 |
liveuser |
1307 |
#回傳結果
|
|
|
1308 |
return $result;
|
| 226 |
liveuser |
1309 |
|
| 3 |
liveuser |
1310 |
}#if end
|
|
|
1311 |
|
| 226 |
liveuser |
1312 |
#將 $string 分割成一個個字元,並存到陣列 #stringCharArray
|
|
|
1313 |
$stringCharArray=str_split($conf["stringIn"]);
|
| 3 |
liveuser |
1314 |
|
|
|
1315 |
#取得分割成幾個字元
|
|
|
1316 |
$stringCharArrayCounts=count($stringCharArray);
|
|
|
1317 |
|
|
|
1318 |
#如果沒有限定要前面幾個字則將全部都轉成ASCII
|
|
|
1319 |
if(!isset($conf["wordsLong"])){
|
| 226 |
liveuser |
1320 |
|
| 3 |
liveuser |
1321 |
$conf["wordsLong"]=$stringCharArrayCounts;
|
| 226 |
liveuser |
1322 |
|
| 3 |
liveuser |
1323 |
}#if end
|
|
|
1324 |
|
|
|
1325 |
#將前面 $wordsLong 個字轉換成ASCII並存到 $charASCII 陣列裏面
|
|
|
1326 |
for($i=0;$i<$conf["wordsLong"];$i++){
|
| 226 |
liveuser |
1327 |
|
|
|
1328 |
$charASCII[$i]=ord($stringCharArray[$i]);
|
|
|
1329 |
|
| 3 |
liveuser |
1330 |
}#for end
|
| 226 |
liveuser |
1331 |
|
| 3 |
liveuser |
1332 |
#取得總共有幾個字的ACSII
|
|
|
1333 |
$result["dataCounts"]=count($charASCII);
|
|
|
1334 |
|
|
|
1335 |
#取得每個字轉好的ACSII陣列
|
|
|
1336 |
$result["acsiiArray"]=$charASCII;
|
|
|
1337 |
|
|
|
1338 |
#設置執行正常
|
|
|
1339 |
$result["status"]="true";
|
|
|
1340 |
|
|
|
1341 |
#回傳結果
|
| 226 |
liveuser |
1342 |
return $result;
|
|
|
1343 |
|
| 3 |
liveuser |
1344 |
}#function StringToASCII end
|
|
|
1345 |
|
|
|
1346 |
/*
|
|
|
1347 |
#函式說明:
|
|
|
1348 |
#將數字字串轉換成實際的數字
|
|
|
1349 |
#回傳結果:
|
|
|
1350 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
1351 |
#$result["error"],錯誤訊息陣列.
|
|
|
1352 |
#$result["function"],當前執行的函數名稱.
|
|
|
1353 |
#$result["content"],實際的數字.
|
|
|
1354 |
#$result["ori"],未轉換的內容.
|
|
|
1355 |
#必填參數:
|
|
|
1356 |
#$conf["stringIn"],字串,要處理度數字字串。
|
|
|
1357 |
$conf["stringIn"]="";
|
|
|
1358 |
#可省略參數:
|
|
|
1359 |
#無.
|
|
|
1360 |
#參考資料:
|
|
|
1361 |
#http://www.phpf1.com/tutorial/php-string-to-int.html
|
|
|
1362 |
#備註:
|
|
|
1363 |
#無.
|
|
|
1364 |
*/
|
|
|
1365 |
public static function stringIntToInt(&$conf){
|
|
|
1366 |
|
|
|
1367 |
#初始化要回傳的內容
|
|
|
1368 |
$result=array();
|
|
|
1369 |
|
|
|
1370 |
#取得當前執行的函數名稱
|
|
|
1371 |
$result["function"]=__FUNCTION__;
|
|
|
1372 |
|
|
|
1373 |
#如果 $conf 不為陣列
|
|
|
1374 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1375 |
|
| 3 |
liveuser |
1376 |
#設置執行失敗
|
|
|
1377 |
$result["status"]="false";
|
| 226 |
liveuser |
1378 |
|
| 3 |
liveuser |
1379 |
#設置執行錯誤訊息
|
|
|
1380 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1381 |
|
|
|
1382 |
#如果傳入的參數為 null
|
|
|
1383 |
if($conf==null){
|
| 226 |
liveuser |
1384 |
|
| 3 |
liveuser |
1385 |
#設置執行錯誤訊息
|
|
|
1386 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1387 |
|
| 3 |
liveuser |
1388 |
}#if end
|
|
|
1389 |
|
|
|
1390 |
#回傳結果
|
|
|
1391 |
return $result;
|
| 226 |
liveuser |
1392 |
|
| 3 |
liveuser |
1393 |
}#if end
|
|
|
1394 |
|
|
|
1395 |
#檢查參數
|
|
|
1396 |
#函式說明:
|
|
|
1397 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1398 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1399 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1400 |
#$result["function"],當前執行的函式名稱.
|
|
|
1401 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1402 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1403 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1404 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1405 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1406 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1407 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1408 |
#必填寫的參數:
|
|
|
1409 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1410 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1411 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1412 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1413 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
1414 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1415 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1416 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1417 |
#可以省略的參數:
|
|
|
1418 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1419 |
#$conf["canBeEmptyString"]="false";
|
|
|
1420 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1421 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
1422 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1423 |
#$conf["skipableVariableType"]=array();
|
|
|
1424 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1425 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
1426 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1427 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1428 |
#參考資料來源:
|
|
|
1429 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1430 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1431 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1432 |
|
|
|
1433 |
#如果檢查有誤
|
|
|
1434 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1435 |
|
| 3 |
liveuser |
1436 |
#設置錯誤識別
|
|
|
1437 |
$result["status"]="false";
|
| 226 |
liveuser |
1438 |
|
| 3 |
liveuser |
1439 |
#設置錯誤訊息
|
|
|
1440 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1441 |
|
| 3 |
liveuser |
1442 |
#回傳結果
|
|
|
1443 |
return $result;
|
| 226 |
liveuser |
1444 |
|
| 3 |
liveuser |
1445 |
}#if end
|
| 226 |
liveuser |
1446 |
|
| 3 |
liveuser |
1447 |
#如果檢查不通過
|
|
|
1448 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1449 |
|
| 3 |
liveuser |
1450 |
#設置錯誤識別
|
|
|
1451 |
$result["status"]="false";
|
| 226 |
liveuser |
1452 |
|
| 3 |
liveuser |
1453 |
#設置錯誤訊息
|
|
|
1454 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1455 |
|
| 3 |
liveuser |
1456 |
#回傳結果
|
|
|
1457 |
return $result;
|
| 226 |
liveuser |
1458 |
|
| 3 |
liveuser |
1459 |
}#if end
|
| 226 |
liveuser |
1460 |
|
| 3 |
liveuser |
1461 |
#取得原始的內容
|
|
|
1462 |
$result["ori"]=$conf["stringIn"];
|
|
|
1463 |
|
|
|
1464 |
#取得轉換好的數字
|
|
|
1465 |
$result["content"]=(int)$conf["stringIn"];
|
|
|
1466 |
|
|
|
1467 |
#設置執行正常
|
|
|
1468 |
$result["status"]="true";
|
|
|
1469 |
|
|
|
1470 |
#回傳結果
|
|
|
1471 |
return $result;
|
| 226 |
liveuser |
1472 |
|
| 3 |
liveuser |
1473 |
}#function stringIntToInt end
|
|
|
1474 |
|
|
|
1475 |
/*
|
|
|
1476 |
#函式說明:
|
| 218 |
liveuser |
1477 |
#將字串中的特定內容取代.
|
|
|
1478 |
#回傳結果:
|
|
|
1479 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1480 |
#$result["function"],當前執行的函數.
|
|
|
1481 |
#$result["content"],爲處理好的字串.
|
|
|
1482 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
1483 |
#$result["argu"],使用的參數.
|
| 218 |
liveuser |
1484 |
#必填參數:
|
|
|
1485 |
#$conf["stringIn"],字串,爲要處理的字串
|
|
|
1486 |
$conf["stringIn"]="";
|
|
|
1487 |
#$conf["selectedCharacter"],字串,爲被選擇要處理的字串/字元,\n」代表換行,「\t」代表tab鍵的間隔.
|
|
|
1488 |
$conf["selectedCharacter"]="";
|
|
|
1489 |
#$conf["changeTo"],字串,爲被選擇的字元要換成什麼字串/字元.
|
|
|
1490 |
$conf["changeTo"]="";
|
|
|
1491 |
#參考資料:
|
|
|
1492 |
#無.
|
|
|
1493 |
#備註:
|
|
|
1494 |
#無.
|
|
|
1495 |
*/
|
|
|
1496 |
public static function replaceOnce(&$conf){
|
| 226 |
liveuser |
1497 |
|
| 218 |
liveuser |
1498 |
#初始化要回傳的結果
|
|
|
1499 |
$result=array();
|
| 226 |
liveuser |
1500 |
|
| 218 |
liveuser |
1501 |
#設置當前執行函數
|
|
|
1502 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1503 |
|
| 218 |
liveuser |
1504 |
#初始化要回傳的主要內容
|
|
|
1505 |
$result["content"]="";
|
|
|
1506 |
|
|
|
1507 |
#如果 $conf 不為陣列
|
|
|
1508 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1509 |
|
| 218 |
liveuser |
1510 |
#設置執行失敗
|
|
|
1511 |
$result["status"]="false";
|
| 226 |
liveuser |
1512 |
|
| 218 |
liveuser |
1513 |
#設置執行錯誤訊息
|
|
|
1514 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1515 |
|
|
|
1516 |
#如果傳入的參數為 null
|
|
|
1517 |
if($conf==null){
|
| 226 |
liveuser |
1518 |
|
| 218 |
liveuser |
1519 |
#設置執行錯誤訊息
|
|
|
1520 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1521 |
|
| 218 |
liveuser |
1522 |
}#if end
|
|
|
1523 |
|
|
|
1524 |
#回傳結果
|
|
|
1525 |
return $result;
|
| 226 |
liveuser |
1526 |
|
| 218 |
liveuser |
1527 |
}#if end
|
|
|
1528 |
|
| 226 |
liveuser |
1529 |
#取得參數
|
| 218 |
liveuser |
1530 |
$result["argu"]=$conf;
|
|
|
1531 |
|
|
|
1532 |
#函式說明:
|
|
|
1533 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1534 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1535 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1536 |
#$result["function"],當前執行的函式名稱.
|
|
|
1537 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1538 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1539 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1540 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1541 |
#必填寫的參數:
|
|
|
1542 |
#$conf["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
1543 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
1544 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1545 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("stringIn","selectedCharacter","changeTo");
|
| 226 |
liveuser |
1546 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 218 |
liveuser |
1547 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1548 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1549 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
1550 |
#可以省略的參數:
|
|
|
1551 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
1552 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
1553 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些變數不可以為空字串或集合.
|
|
|
1554 |
#$conf["variableCheck.checkArguments"]["skipableVariableCanNotBeEmpty"]=array("");
|
|
|
1555 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1556 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("selectedCharacter","changeTo");
|
| 226 |
liveuser |
1557 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 218 |
liveuser |
1558 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
1559 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
1560 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(array("<",">","=","//","'","$","%","&","|","/*","*/","#","\""),null);
|
|
|
1561 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
1562 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
1563 |
|
| 218 |
liveuser |
1564 |
#如果檢查失敗
|
|
|
1565 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1566 |
|
| 218 |
liveuser |
1567 |
#設置執行失敗
|
|
|
1568 |
$result["status"]="false";
|
| 226 |
liveuser |
1569 |
|
| 218 |
liveuser |
1570 |
#設置錯誤訊息
|
|
|
1571 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1572 |
|
| 218 |
liveuser |
1573 |
#回傳結果
|
|
|
1574 |
return $result;
|
| 226 |
liveuser |
1575 |
|
| 218 |
liveuser |
1576 |
}#if end
|
| 226 |
liveuser |
1577 |
|
| 218 |
liveuser |
1578 |
#如果檢查不通過
|
|
|
1579 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1580 |
|
| 218 |
liveuser |
1581 |
#設置執行失敗
|
|
|
1582 |
$result["status"]="false";
|
| 226 |
liveuser |
1583 |
|
| 218 |
liveuser |
1584 |
#設置錯誤訊息
|
|
|
1585 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1586 |
|
| 218 |
liveuser |
1587 |
#回傳結果
|
|
|
1588 |
return $result;
|
| 226 |
liveuser |
1589 |
|
| 218 |
liveuser |
1590 |
}#if end
|
| 226 |
liveuser |
1591 |
|
| 218 |
liveuser |
1592 |
#只取代一次
|
|
|
1593 |
$one=1;
|
| 226 |
liveuser |
1594 |
|
| 218 |
liveuser |
1595 |
#取得進行替換後的結果
|
|
|
1596 |
$result["content"]=str_replace($conf["selectedCharacter"],$conf["changeTo"],$conf["stringIn"],$one);
|
|
|
1597 |
|
|
|
1598 |
#檢查變數內容
|
|
|
1599 |
$result["status"]="true";
|
| 226 |
liveuser |
1600 |
|
| 218 |
liveuser |
1601 |
#回傳經過整理的字串
|
|
|
1602 |
return $result;
|
| 226 |
liveuser |
1603 |
|
| 218 |
liveuser |
1604 |
}#function replaceOnce end
|
|
|
1605 |
|
|
|
1606 |
/*
|
|
|
1607 |
#函式說明:
|
| 3 |
liveuser |
1608 |
#處理字串避免網頁出錯
|
|
|
1609 |
#回傳結果:
|
|
|
1610 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1611 |
#$result["function"],當前執行的函數.
|
|
|
1612 |
#$result["content"],爲處理好的字串.
|
|
|
1613 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
1614 |
#$result["argu"],使用的參數.
|
| 3 |
liveuser |
1615 |
#必填參數:
|
|
|
1616 |
#$conf["stringIn"],字串,爲要處理的字串
|
|
|
1617 |
$conf["stringIn"]="";
|
|
|
1618 |
#可省略參數:
|
|
|
1619 |
#$conf["selectedCharacter"],字串陣列,爲被選擇要處理的字串/字元,須爲陣列值。若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1620 |
#$conf["selectedCharacter"]=array("");
|
|
|
1621 |
#$conf["changeTo"],字串陣列,爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1622 |
#$conf["changeTo"]=array("");
|
|
|
1623 |
#參考資料:
|
|
|
1624 |
#無.
|
|
|
1625 |
#備註:
|
|
|
1626 |
#無.
|
| 226 |
liveuser |
1627 |
*/
|
| 3 |
liveuser |
1628 |
public static function correctCharacter(&$conf){
|
|
|
1629 |
|
|
|
1630 |
#初始化要回傳的結果
|
|
|
1631 |
$result=array();
|
| 226 |
liveuser |
1632 |
|
| 3 |
liveuser |
1633 |
#設置當前執行函數
|
| 218 |
liveuser |
1634 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1635 |
|
| 3 |
liveuser |
1636 |
#初始化要回傳的主要內容
|
|
|
1637 |
$result["content"]="";
|
|
|
1638 |
|
|
|
1639 |
#如果 $conf 不為陣列
|
|
|
1640 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1641 |
|
| 3 |
liveuser |
1642 |
#設置執行失敗
|
|
|
1643 |
$result["status"]="false";
|
| 226 |
liveuser |
1644 |
|
| 3 |
liveuser |
1645 |
#設置執行錯誤訊息
|
|
|
1646 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1647 |
|
|
|
1648 |
#如果傳入的參數為 null
|
|
|
1649 |
if($conf==null){
|
| 226 |
liveuser |
1650 |
|
| 3 |
liveuser |
1651 |
#設置執行錯誤訊息
|
|
|
1652 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1653 |
|
| 3 |
liveuser |
1654 |
}#if end
|
|
|
1655 |
|
|
|
1656 |
#回傳結果
|
|
|
1657 |
return $result;
|
| 226 |
liveuser |
1658 |
|
| 3 |
liveuser |
1659 |
}#if end
|
|
|
1660 |
|
| 226 |
liveuser |
1661 |
#取得參數
|
| 218 |
liveuser |
1662 |
$result["argu"]=$conf;
|
| 3 |
liveuser |
1663 |
|
|
|
1664 |
#函式說明:
|
|
|
1665 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1666 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1667 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1668 |
#$result["function"],當前執行的函式名稱.
|
|
|
1669 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1670 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1671 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1672 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1673 |
#必填寫的參數:
|
|
|
1674 |
#$conf["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
1675 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
1676 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1677 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1678 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1679 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1680 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1681 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
| 218 |
liveuser |
1682 |
#可以省略的參數:
|
| 3 |
liveuser |
1683 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
1684 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
1685 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些變數不可以為空字串或集合.
|
|
|
1686 |
$conf["variableCheck.checkArguments"]["skipableVariableCanNotBeEmpty"]=array("selectedCharacter");
|
|
|
1687 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1688 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("selectedCharacter","changeTo");
|
| 226 |
liveuser |
1689 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1690 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
1691 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
1692 |
$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(array("<",">","=","//","'","$","%","&","|","/*","*/","#","\""),null);
|
|
|
1693 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
1694 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
1695 |
|
| 3 |
liveuser |
1696 |
#如果檢查失敗
|
|
|
1697 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1698 |
|
| 3 |
liveuser |
1699 |
#設置執行失敗
|
|
|
1700 |
$result["status"]="false";
|
| 226 |
liveuser |
1701 |
|
| 3 |
liveuser |
1702 |
#設置錯誤訊息
|
|
|
1703 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1704 |
|
| 3 |
liveuser |
1705 |
#回傳結果
|
|
|
1706 |
return $result;
|
| 226 |
liveuser |
1707 |
|
| 3 |
liveuser |
1708 |
}#if end
|
| 226 |
liveuser |
1709 |
|
| 3 |
liveuser |
1710 |
#如果檢查不通過
|
|
|
1711 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1712 |
|
| 3 |
liveuser |
1713 |
#設置執行失敗
|
|
|
1714 |
$result["status"]="false";
|
| 226 |
liveuser |
1715 |
|
| 3 |
liveuser |
1716 |
#設置錯誤訊息
|
|
|
1717 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1718 |
|
| 3 |
liveuser |
1719 |
#回傳結果
|
|
|
1720 |
return $result;
|
| 226 |
liveuser |
1721 |
|
| 218 |
liveuser |
1722 |
}#if end
|
| 3 |
liveuser |
1723 |
|
|
|
1724 |
#取得有幾種字串要處理
|
|
|
1725 |
$num=count($conf["selectedCharacter"]);
|
|
|
1726 |
|
|
|
1727 |
#如果 $conf["changeTo"] 有設定
|
|
|
1728 |
if(isset($conf["changeTo"])){
|
| 226 |
liveuser |
1729 |
|
| 3 |
liveuser |
1730 |
#如果 count($conf["selectedCharacter"]) 與 count($conf["changeTo"]) 不相等
|
|
|
1731 |
if(count($conf["selectedCharacter"])!=count($conf["changeTo"])){
|
| 226 |
liveuser |
1732 |
|
| 3 |
liveuser |
1733 |
#設置執行失敗
|
|
|
1734 |
$result["status"]="false";
|
| 226 |
liveuser |
1735 |
|
| 3 |
liveuser |
1736 |
#設置錯誤訊息
|
|
|
1737 |
$result["error"][]="\$conf[\"selectedCharacter\"] 與 \$conf[\"changeTo\"] 的元素數量不相等!";
|
| 226 |
liveuser |
1738 |
|
| 3 |
liveuser |
1739 |
#回傳結果
|
|
|
1740 |
return $result;
|
| 226 |
liveuser |
1741 |
|
| 3 |
liveuser |
1742 |
}#if end
|
| 226 |
liveuser |
1743 |
|
| 3 |
liveuser |
1744 |
}#if end
|
|
|
1745 |
|
|
|
1746 |
#如果 $conf["changeTo"] 爲空,則將每個要處理的字串,替換成""。
|
|
|
1747 |
if(!isset($conf["changeTo"])){
|
|
|
1748 |
|
|
|
1749 |
#有幾種要處理的字元就放進去幾個要對照替換的字串。
|
|
|
1750 |
for($i=0;$i<$num;$i++){
|
| 226 |
liveuser |
1751 |
|
| 3 |
liveuser |
1752 |
$conf["changeTo"][$i]="";
|
|
|
1753 |
|
|
|
1754 |
}#for end
|
|
|
1755 |
|
|
|
1756 |
}#if end
|
|
|
1757 |
|
|
|
1758 |
#處理 $num 次
|
|
|
1759 |
for($i=0;$i<$num;$i++){
|
|
|
1760 |
|
|
|
1761 |
#如果要處理的字元為空字串
|
|
|
1762 |
if($conf["selectedCharacter"][$i]==""){
|
| 226 |
liveuser |
1763 |
|
| 3 |
liveuser |
1764 |
#debug
|
|
|
1765 |
#echo "<p>空字串不處理</p>";
|
| 226 |
liveuser |
1766 |
|
| 3 |
liveuser |
1767 |
#跳過該此處理
|
|
|
1768 |
continue;
|
| 226 |
liveuser |
1769 |
|
| 3 |
liveuser |
1770 |
}#if end
|
|
|
1771 |
|
|
|
1772 |
#進行轉換
|
|
|
1773 |
$conf["stringIn"] = str_replace($conf["selectedCharacter"][$i],$conf["changeTo"][$i],$conf["stringIn"]);
|
|
|
1774 |
|
|
|
1775 |
}#for end
|
|
|
1776 |
|
|
|
1777 |
#取得處理好的結果
|
|
|
1778 |
$result["content"]=$conf["stringIn"];
|
|
|
1779 |
|
|
|
1780 |
#檢查變數內容
|
|
|
1781 |
$result["status"]="true";
|
| 226 |
liveuser |
1782 |
|
| 3 |
liveuser |
1783 |
#回傳經過整理的字串
|
|
|
1784 |
return $result;
|
|
|
1785 |
|
|
|
1786 |
}#function correctCharacter end
|
| 226 |
liveuser |
1787 |
|
| 3 |
liveuser |
1788 |
/*
|
|
|
1789 |
#函式說明:
|
|
|
1790 |
#處理多個字串避免網頁出錯
|
|
|
1791 |
#回傳結果:
|
|
|
1792 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗.
|
|
|
1793 |
#$result["function"],當前執行的函數.
|
|
|
1794 |
#$result["error"],錯誤訊息.
|
|
|
1795 |
#$result["processedStrArray"],處理好的字串陣列.
|
|
|
1796 |
#必填參數:
|
|
|
1797 |
#$conf["stringIn"],字串陣列,爲要處理的字串陣列.
|
|
|
1798 |
#$conf["stringIn"]=array("");
|
|
|
1799 |
#可省略參數:
|
|
|
1800 |
#$conf["selectedCharacter"],字串陣列,爲被選擇要處理的字串/字元,須爲陣列值。若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
| 226 |
liveuser |
1801 |
#$conf["selectedCharacter"]=array("");
|
| 3 |
liveuser |
1802 |
#$conf["changeTo"],字串陣列,爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1803 |
#$conf["changeTo"]=array();
|
|
|
1804 |
#參考資料:
|
|
|
1805 |
#無.
|
|
|
1806 |
#備註:
|
|
|
1807 |
#無.
|
| 226 |
liveuser |
1808 |
*/
|
| 3 |
liveuser |
1809 |
public static function correctMutiStrCharacter(&$conf){
|
| 226 |
liveuser |
1810 |
|
| 3 |
liveuser |
1811 |
#初始化要回傳的結果
|
|
|
1812 |
$result=array();
|
| 226 |
liveuser |
1813 |
|
| 3 |
liveuser |
1814 |
#設置當前執行函數
|
| 226 |
liveuser |
1815 |
$result["function"]=__FUNCTION__;
|
|
|
1816 |
|
| 3 |
liveuser |
1817 |
#初始化要回傳的主要內容
|
|
|
1818 |
$result["content"]="";
|
|
|
1819 |
|
|
|
1820 |
#如果 $conf 不為陣列
|
|
|
1821 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1822 |
|
| 3 |
liveuser |
1823 |
#設置執行失敗
|
|
|
1824 |
$result["status"]="false";
|
| 226 |
liveuser |
1825 |
|
| 3 |
liveuser |
1826 |
#設置執行錯誤訊息
|
|
|
1827 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1828 |
|
|
|
1829 |
#如果傳入的參數為 null
|
|
|
1830 |
if($conf==null){
|
| 226 |
liveuser |
1831 |
|
| 3 |
liveuser |
1832 |
#設置執行錯誤訊息
|
|
|
1833 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1834 |
|
| 3 |
liveuser |
1835 |
}#if end
|
|
|
1836 |
|
|
|
1837 |
#回傳結果
|
|
|
1838 |
return $result;
|
| 226 |
liveuser |
1839 |
|
|
|
1840 |
}#if end
|
|
|
1841 |
|
| 3 |
liveuser |
1842 |
#檢查參數
|
|
|
1843 |
#函式說明:
|
|
|
1844 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1845 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1846 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1847 |
#$result["function"],當前執行的函式名稱.
|
|
|
1848 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1849 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1850 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1851 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1852 |
#必填寫的參數:
|
|
|
1853 |
#$conf["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
1854 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
1855 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1856 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("stringIn");
|
| 226 |
liveuser |
1857 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1858 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
1859 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1860 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
1861 |
#可以省略的參數:
|
|
|
1862 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
1863 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
1864 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1865 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("selectedCharacter","changeTo");
|
| 226 |
liveuser |
1866 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1867 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array");
|
|
|
1868 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
1869 |
$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
1870 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
1871 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
1872 |
|
| 3 |
liveuser |
1873 |
#如果檢查失敗
|
|
|
1874 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1875 |
|
| 3 |
liveuser |
1876 |
#設置執行失敗
|
|
|
1877 |
$result["status"]="false";
|
| 226 |
liveuser |
1878 |
|
| 3 |
liveuser |
1879 |
#設置錯誤訊息
|
|
|
1880 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1881 |
|
| 3 |
liveuser |
1882 |
#回傳結果
|
|
|
1883 |
return $result;
|
| 226 |
liveuser |
1884 |
|
| 3 |
liveuser |
1885 |
}#if end
|
| 226 |
liveuser |
1886 |
|
| 3 |
liveuser |
1887 |
#如果檢查不通過
|
|
|
1888 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1889 |
|
| 3 |
liveuser |
1890 |
#設置執行失敗
|
|
|
1891 |
$result["status"]="false";
|
| 226 |
liveuser |
1892 |
|
| 3 |
liveuser |
1893 |
#設置錯誤訊息
|
|
|
1894 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1895 |
|
| 3 |
liveuser |
1896 |
#回傳結果
|
|
|
1897 |
return $result;
|
| 226 |
liveuser |
1898 |
|
|
|
1899 |
}#if end
|
|
|
1900 |
|
| 3 |
liveuser |
1901 |
#針對每個 $unProcessedStr 的元素執行一次
|
|
|
1902 |
foreach($conf["stringIn"] as $unProcessedStrKey=>$unProcessedStrValue){
|
| 226 |
liveuser |
1903 |
|
| 3 |
liveuser |
1904 |
#如果該行為 ""
|
|
|
1905 |
if($unProcessedStrValue===""){
|
| 226 |
liveuser |
1906 |
|
| 3 |
liveuser |
1907 |
#不處理直接儲存成 ""
|
|
|
1908 |
$result["processedStrArray"][$unProcessedStrKey]="";
|
| 226 |
liveuser |
1909 |
|
| 3 |
liveuser |
1910 |
#跳過該回合
|
|
|
1911 |
continue;
|
| 226 |
liveuser |
1912 |
|
| 3 |
liveuser |
1913 |
}#if end
|
| 226 |
liveuser |
1914 |
|
| 3 |
liveuser |
1915 |
#函式說明:
|
|
|
1916 |
#處理字串避免網頁出錯
|
|
|
1917 |
#回傳結果:
|
|
|
1918 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1919 |
#$result["content"],爲處理好的字串。
|
|
|
1920 |
#$result["error"],錯誤訊息陣列
|
|
|
1921 |
#必填參數:
|
|
|
1922 |
$conf["variableCheck.correctCharacter"]["stringIn"]=$unProcessedStrValue;#爲要處理的字串
|
|
|
1923 |
#可省略參數:
|
| 226 |
liveuser |
1924 |
|
| 3 |
liveuser |
1925 |
#如果 $conf["selectedCharacter"] 有設定
|
|
|
1926 |
if(isset($conf["selectedCharacter"])){
|
| 226 |
liveuser |
1927 |
|
| 3 |
liveuser |
1928 |
$conf["variableCheck.correctCharacter"]["selectedCharacter"]=$conf["selectedCharacter"];#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1929 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
1930 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
| 226 |
liveuser |
1931 |
|
| 3 |
liveuser |
1932 |
}#if end
|
| 226 |
liveuser |
1933 |
|
| 3 |
liveuser |
1934 |
#如果 $conf["changeTo"] 有設定
|
|
|
1935 |
if(isset($conf["changeTo"])){
|
| 226 |
liveuser |
1936 |
|
| 3 |
liveuser |
1937 |
$conf["variableCheck.correctCharacter"]["changeTo"]=$conf["changeTo"];#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
| 226 |
liveuser |
1938 |
|
|
|
1939 |
}#if end
|
|
|
1940 |
|
| 3 |
liveuser |
1941 |
$processedStrResult=stringProcess::correctCharacter($conf["variableCheck.correctCharacter"]);
|
| 226 |
liveuser |
1942 |
unset($conf["variableCheck.correctCharacter"]);
|
|
|
1943 |
|
|
|
1944 |
#如果 $processedStrResult["status"] 等於 "false"
|
| 3 |
liveuser |
1945 |
if($processedStrResult["status"]=="false"){
|
| 226 |
liveuser |
1946 |
|
| 3 |
liveuser |
1947 |
#設置錯誤
|
|
|
1948 |
$result["status"]="false";
|
| 226 |
liveuser |
1949 |
|
| 3 |
liveuser |
1950 |
#設置錯誤訊息
|
|
|
1951 |
$result["error"]=$processedStrResult;
|
| 226 |
liveuser |
1952 |
|
| 3 |
liveuser |
1953 |
#回傳結果
|
|
|
1954 |
return $result;
|
| 226 |
liveuser |
1955 |
|
| 3 |
liveuser |
1956 |
}#if end
|
| 226 |
liveuser |
1957 |
|
| 3 |
liveuser |
1958 |
#取得處理好的字串
|
|
|
1959 |
$result["processedStrArray"][$unProcessedStrKey]=$processedStrResult["content"];
|
| 226 |
liveuser |
1960 |
|
| 3 |
liveuser |
1961 |
}#foreach end
|
| 226 |
liveuser |
1962 |
|
| 3 |
liveuser |
1963 |
#執行到這邊代表執行成功
|
|
|
1964 |
$result["status"]="true";
|
| 226 |
liveuser |
1965 |
|
| 3 |
liveuser |
1966 |
#回傳結果
|
|
|
1967 |
return $result;
|
| 226 |
liveuser |
1968 |
|
| 3 |
liveuser |
1969 |
}#function correctMutiStrCharacter end
|
|
|
1970 |
|
|
|
1971 |
/*
|
|
|
1972 |
#函式說明:
|
|
|
1973 |
#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
|
|
|
1974 |
#回傳結果:
|
|
|
1975 |
#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
|
|
|
1976 |
#$result["function"],當前執行的函數.
|
|
|
1977 |
#$result["error"],錯誤訊息陣列.
|
|
|
1978 |
#$result["argu"],使用者參數.
|
|
|
1979 |
#$result["changedPath"],處理完後回傳的目錄字串.
|
|
|
1980 |
#$result["oriPath"],原始的路徑字串
|
|
|
1981 |
#必填參數:
|
|
|
1982 |
#$conf["dirStr"],字串,要處理的檔案目錄字串.
|
|
|
1983 |
$conf["dirStr"]="";
|
|
|
1984 |
#可省略參數:
|
|
|
1985 |
#無.
|
|
|
1986 |
#參考資料:
|
|
|
1987 |
#無.
|
|
|
1988 |
#備註:
|
|
|
1989 |
#考慮用realpath取代
|
|
|
1990 |
*/
|
|
|
1991 |
public static function changeDirByDotDotSolidus(&$conf){
|
| 226 |
liveuser |
1992 |
|
| 3 |
liveuser |
1993 |
#初始化要回傳的內容
|
|
|
1994 |
$result=array();
|
|
|
1995 |
|
|
|
1996 |
#取得當前執行的函數名稱
|
|
|
1997 |
$result["function"]=__FUNCTION__;
|
|
|
1998 |
|
|
|
1999 |
#如果 $conf 不為陣列
|
|
|
2000 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2001 |
|
| 3 |
liveuser |
2002 |
#設置執行失敗
|
|
|
2003 |
$result["status"]="false";
|
| 226 |
liveuser |
2004 |
|
| 3 |
liveuser |
2005 |
#設置執行錯誤訊息
|
|
|
2006 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2007 |
|
|
|
2008 |
#如果傳入的參數為 null
|
|
|
2009 |
if($conf==null){
|
| 226 |
liveuser |
2010 |
|
| 3 |
liveuser |
2011 |
#設置執行錯誤訊息
|
|
|
2012 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2013 |
|
| 3 |
liveuser |
2014 |
}#if end
|
|
|
2015 |
|
|
|
2016 |
#回傳結果
|
|
|
2017 |
return $result;
|
| 226 |
liveuser |
2018 |
|
| 3 |
liveuser |
2019 |
}#if end
|
|
|
2020 |
|
|
|
2021 |
#取得使用的參數
|
|
|
2022 |
$result["argu"]=$conf;
|
|
|
2023 |
|
|
|
2024 |
#檢查參數
|
|
|
2025 |
#函式說明:
|
|
|
2026 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2027 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2028 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2029 |
#$result["function"],當前執行的函式名稱.
|
|
|
2030 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2031 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2032 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2033 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2034 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2035 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2036 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2037 |
#必填寫的參數:
|
|
|
2038 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2039 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2040 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2041 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dirStr");
|
| 226 |
liveuser |
2042 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
2043 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
2044 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2045 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2046 |
#可以省略的參數:
|
|
|
2047 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2048 |
#$conf["canBeEmptyString"]="false";
|
|
|
2049 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2050 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wordsLong");
|
| 226 |
liveuser |
2051 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2052 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2053 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2054 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
2055 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2056 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2057 |
#參考資料來源:
|
|
|
2058 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2059 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2060 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2061 |
|
|
|
2062 |
#如果檢查有誤
|
|
|
2063 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2064 |
|
| 3 |
liveuser |
2065 |
#設置錯誤識別
|
|
|
2066 |
$result["status"]="false";
|
| 226 |
liveuser |
2067 |
|
| 3 |
liveuser |
2068 |
#設置錯誤訊息
|
|
|
2069 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2070 |
|
| 3 |
liveuser |
2071 |
#回傳結果
|
|
|
2072 |
return $result;
|
| 226 |
liveuser |
2073 |
|
| 3 |
liveuser |
2074 |
}#if end
|
| 226 |
liveuser |
2075 |
|
| 3 |
liveuser |
2076 |
#如果檢查不通過
|
|
|
2077 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2078 |
|
| 3 |
liveuser |
2079 |
#設置錯誤識別
|
|
|
2080 |
$result["status"]="false";
|
| 226 |
liveuser |
2081 |
|
| 3 |
liveuser |
2082 |
#設置錯誤訊息
|
|
|
2083 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2084 |
|
| 3 |
liveuser |
2085 |
#回傳結果
|
|
|
2086 |
return $result;
|
| 226 |
liveuser |
2087 |
|
| 3 |
liveuser |
2088 |
}#if end
|
| 226 |
liveuser |
2089 |
|
| 3 |
liveuser |
2090 |
#初始化儲存原始路徑字串
|
|
|
2091 |
$result["oriPath"]=$conf["dirStr"];
|
| 226 |
liveuser |
2092 |
|
| 3 |
liveuser |
2093 |
#初始化用來儲存輸出內容的元素.
|
|
|
2094 |
$result["changedPath"]="";
|
| 226 |
liveuser |
2095 |
|
| 3 |
liveuser |
2096 |
#初始化暫存的字串目錄
|
|
|
2097 |
$tempDirStrArray=array();
|
| 226 |
liveuser |
2098 |
|
| 3 |
liveuser |
2099 |
#用 / 進行分割
|
|
|
2100 |
#函式說明:
|
|
|
2101 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
2102 |
#回傳的參數:
|
|
|
2103 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2104 |
#$result["error"],錯誤訊息陣列
|
|
|
2105 |
#$result["function"],當前執行的函數名稱.
|
|
|
2106 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
2107 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
2108 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
2109 |
#必填參數:
|
|
|
2110 |
$conf["stringProcess::spiltString"]["stringIn"]=$conf["dirStr"];#要處理的字串。
|
|
|
2111 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="/";#爲以哪個符號作爲分割
|
|
|
2112 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
2113 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
2114 |
|
| 3 |
liveuser |
2115 |
#如果分割失敗
|
|
|
2116 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
2117 |
|
| 3 |
liveuser |
2118 |
#設置錯誤識別
|
|
|
2119 |
$result["status"]="false";
|
| 226 |
liveuser |
2120 |
|
| 3 |
liveuser |
2121 |
#設置錯誤訊息
|
|
|
2122 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
2123 |
|
| 3 |
liveuser |
2124 |
#回傳結果
|
|
|
2125 |
return $result;
|
| 226 |
liveuser |
2126 |
|
| 3 |
liveuser |
2127 |
}#if end
|
| 226 |
liveuser |
2128 |
|
| 3 |
liveuser |
2129 |
#分成幾段就執行幾次
|
|
|
2130 |
for($i=0;$i<$spiltString["dataCounts"];$i++){
|
| 226 |
liveuser |
2131 |
|
| 3 |
liveuser |
2132 |
#如果是往上層目錄的「..」
|
|
|
2133 |
if($spiltString["dataArray"][$i]===".."){
|
| 226 |
liveuser |
2134 |
|
| 3 |
liveuser |
2135 |
#如果陣列不為空
|
|
|
2136 |
if($tempDirStrArray!==array()){
|
| 226 |
liveuser |
2137 |
|
| 3 |
liveuser |
2138 |
#如果前面有非 ".." 的目錄名稱
|
|
|
2139 |
if($tempDirStrArray[count($tempDirStrArray)-1]!==".."){
|
| 226 |
liveuser |
2140 |
|
| 3 |
liveuser |
2141 |
#函式說明:
|
|
|
2142 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
2143 |
#回傳結果:
|
|
|
2144 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2145 |
#$result["error"],錯誤訊息
|
|
|
2146 |
#$result["function"],當前執行的函數
|
|
|
2147 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
2148 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
2149 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
2150 |
#必填參數:
|
|
|
2151 |
$conf["arrays::eraseElement"]["rawInputArray"]=$tempDirStrArray;#要處理的原始數字陣列
|
| 226 |
liveuser |
2152 |
$conf["arrays::eraseElement"]["eraseElementKey"]="".(count($tempDirStrArray)-1)."";#要移除的元素key值
|
| 3 |
liveuser |
2153 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
2154 |
unset($conf["arrays::eraseElement"]);
|
| 226 |
liveuser |
2155 |
|
| 3 |
liveuser |
2156 |
#如果移除失敗
|
|
|
2157 |
if($eraseElement["status"]=="false"){
|
| 226 |
liveuser |
2158 |
|
| 3 |
liveuser |
2159 |
#設置錯誤識別
|
|
|
2160 |
$result["status"]="false";
|
| 226 |
liveuser |
2161 |
|
| 3 |
liveuser |
2162 |
#設置錯誤訊息
|
|
|
2163 |
$result["error"]=$eraseElement;
|
| 226 |
liveuser |
2164 |
|
| 3 |
liveuser |
2165 |
#回傳結果
|
|
|
2166 |
return $result;
|
| 226 |
liveuser |
2167 |
|
| 3 |
liveuser |
2168 |
}#if end
|
| 226 |
liveuser |
2169 |
|
| 3 |
liveuser |
2170 |
#取得新陣列
|
|
|
2171 |
$tempDirStrArray=$eraseElement["content"]["byNumber"];
|
| 226 |
liveuser |
2172 |
|
| 3 |
liveuser |
2173 |
}#if end
|
| 226 |
liveuser |
2174 |
|
|
|
2175 |
#反之
|
| 3 |
liveuser |
2176 |
else{
|
| 226 |
liveuser |
2177 |
|
| 3 |
liveuser |
2178 |
#儲存 ".."
|
|
|
2179 |
$tempDirStrArray[]=$spiltString["dataArray"][$i];
|
| 226 |
liveuser |
2180 |
|
| 3 |
liveuser |
2181 |
}
|
| 226 |
liveuser |
2182 |
|
|
|
2183 |
}#if end
|
|
|
2184 |
|
| 3 |
liveuser |
2185 |
#反之
|
|
|
2186 |
else{
|
| 226 |
liveuser |
2187 |
|
| 3 |
liveuser |
2188 |
#儲存 ".."
|
|
|
2189 |
$tempDirStrArray[]=$spiltString["dataArray"][$i];
|
| 226 |
liveuser |
2190 |
|
| 3 |
liveuser |
2191 |
}#else end
|
| 226 |
liveuser |
2192 |
|
| 3 |
liveuser |
2193 |
}#if end
|
| 226 |
liveuser |
2194 |
|
| 3 |
liveuser |
2195 |
#反之
|
|
|
2196 |
else{
|
| 226 |
liveuser |
2197 |
|
| 3 |
liveuser |
2198 |
#儲存路徑片段
|
|
|
2199 |
$tempDirStrArray[]=$spiltString["dataArray"][$i];
|
| 226 |
liveuser |
2200 |
|
| 3 |
liveuser |
2201 |
}#else end
|
| 226 |
liveuser |
2202 |
|
| 3 |
liveuser |
2203 |
}#for end
|
| 226 |
liveuser |
2204 |
|
| 3 |
liveuser |
2205 |
#debug
|
|
|
2206 |
#var_dump($tempDirStrArray);exit;
|
| 226 |
liveuser |
2207 |
|
| 3 |
liveuser |
2208 |
#檢查 $conf["dirStr"] 是否為 「/」 開頭
|
|
|
2209 |
#函式說明:
|
|
|
2210 |
#取得符合特定字首與字尾的字串
|
|
|
2211 |
#回傳結果:
|
|
|
2212 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
2213 |
#$result["function"],當前執行的函數名稱.
|
|
|
2214 |
#$result["error"],錯誤訊息陣列.
|
|
|
2215 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
2216 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
2217 |
#必填參數:
|
|
|
2218 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
2219 |
$conf["search::getMeetConditionsString"]["checkString"]=$conf["dirStr"];
|
|
|
2220 |
#可省略參數:
|
|
|
2221 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
2222 |
$conf["search::getMeetConditionsString"]["frontWord"]="/";
|
|
|
2223 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
2224 |
#$conf["tailWord"]="";
|
|
|
2225 |
#參考資料:
|
|
|
2226 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
2227 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
2228 |
unset($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
2229 |
|
| 3 |
liveuser |
2230 |
#如果尋找關鍵字失敗
|
|
|
2231 |
if($getMeetConditionsString["status"]=="false"){
|
| 226 |
liveuser |
2232 |
|
| 3 |
liveuser |
2233 |
#設置錯誤識別
|
|
|
2234 |
$result["status"]="false";
|
| 226 |
liveuser |
2235 |
|
| 3 |
liveuser |
2236 |
#設置錯誤訊息
|
|
|
2237 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
2238 |
|
| 3 |
liveuser |
2239 |
#回傳結果
|
|
|
2240 |
return $result;
|
| 226 |
liveuser |
2241 |
|
| 3 |
liveuser |
2242 |
}#if end
|
| 226 |
liveuser |
2243 |
|
| 3 |
liveuser |
2244 |
#如果有關鍵字「/」在開頭
|
|
|
2245 |
if($getMeetConditionsString["founded"]=="true"){
|
| 226 |
liveuser |
2246 |
|
| 3 |
liveuser |
2247 |
#初始化改變好的路徑為「/」開頭
|
|
|
2248 |
$result["changedPath"]="/";
|
| 226 |
liveuser |
2249 |
|
| 3 |
liveuser |
2250 |
}#if end
|
| 226 |
liveuser |
2251 |
|
| 3 |
liveuser |
2252 |
#$tempDirStrArray有幾個元素就執行幾次
|
|
|
2253 |
for($i=0;$i<count($tempDirStrArray);$i++){
|
| 226 |
liveuser |
2254 |
|
| 3 |
liveuser |
2255 |
#如果是最後一個元素
|
|
|
2256 |
if($i==(count($tempDirStrArray)-1)){
|
| 226 |
liveuser |
2257 |
|
| 3 |
liveuser |
2258 |
#檢查 $conf["dirStr"] 是否有 「/」 結尾
|
|
|
2259 |
#函式說明:
|
|
|
2260 |
#取得符合特定字首與字尾的字串
|
|
|
2261 |
#回傳結果:
|
|
|
2262 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
2263 |
#$result["function"],當前執行的函數名稱.
|
|
|
2264 |
#$result["error"],錯誤訊息陣列.
|
|
|
2265 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
2266 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
2267 |
#必填參數:
|
|
|
2268 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
2269 |
$conf["search::getMeetConditionsString"]["checkString"]=$conf["dirStr"];
|
|
|
2270 |
#可省略參數:
|
|
|
2271 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
2272 |
#$conf["search::getMeetConditionsString"]["frontWord"]=".";
|
|
|
2273 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
2274 |
$conf["search::getMeetConditionsString"]["tailWord"]="/";
|
|
|
2275 |
#參考資料:
|
|
|
2276 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
2277 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
2278 |
unset($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
2279 |
|
| 3 |
liveuser |
2280 |
#如果尋找關鍵字失敗
|
|
|
2281 |
if($getMeetConditionsString["status"]=="false"){
|
| 226 |
liveuser |
2282 |
|
| 3 |
liveuser |
2283 |
#設置錯誤識別
|
|
|
2284 |
$result["status"]="false";
|
| 226 |
liveuser |
2285 |
|
| 3 |
liveuser |
2286 |
#設置錯誤訊息
|
|
|
2287 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
2288 |
|
| 3 |
liveuser |
2289 |
#回傳結果
|
|
|
2290 |
return $result;
|
| 226 |
liveuser |
2291 |
|
| 3 |
liveuser |
2292 |
}#if end
|
| 226 |
liveuser |
2293 |
|
| 3 |
liveuser |
2294 |
#如果有關鍵字「/」在結尾
|
|
|
2295 |
if($getMeetConditionsString["founded"]=="true"){
|
| 226 |
liveuser |
2296 |
|
| 3 |
liveuser |
2297 |
#串接直觀的路徑與結尾加上「/」
|
|
|
2298 |
$result["changedPath"]=$result["changedPath"].$tempDirStrArray[$i]."/";
|
| 226 |
liveuser |
2299 |
|
| 3 |
liveuser |
2300 |
}#if end
|
| 226 |
liveuser |
2301 |
|
| 3 |
liveuser |
2302 |
#反之
|
|
|
2303 |
else{
|
| 226 |
liveuser |
2304 |
|
| 3 |
liveuser |
2305 |
#串接直觀的路徑與結尾加上「/」
|
|
|
2306 |
$result["changedPath"]=$result["changedPath"].$tempDirStrArray[$i];
|
| 226 |
liveuser |
2307 |
|
| 3 |
liveuser |
2308 |
}#else end
|
| 226 |
liveuser |
2309 |
|
| 3 |
liveuser |
2310 |
}#if end
|
| 226 |
liveuser |
2311 |
|
|
|
2312 |
#反之
|
| 3 |
liveuser |
2313 |
else{
|
| 226 |
liveuser |
2314 |
|
| 3 |
liveuser |
2315 |
#串接直觀的路徑與結尾加上「/」
|
|
|
2316 |
$result["changedPath"]=$result["changedPath"].$tempDirStrArray[$i]."/";
|
| 226 |
liveuser |
2317 |
|
| 3 |
liveuser |
2318 |
}#else end
|
| 226 |
liveuser |
2319 |
|
| 3 |
liveuser |
2320 |
}#for end
|
| 226 |
liveuser |
2321 |
|
| 3 |
liveuser |
2322 |
#設置執行成功的識別
|
|
|
2323 |
$result["status"]="true";
|
| 226 |
liveuser |
2324 |
|
| 3 |
liveuser |
2325 |
#回傳結果
|
|
|
2326 |
return $result;
|
| 226 |
liveuser |
2327 |
|
| 3 |
liveuser |
2328 |
}#function changeDirByDotDotSolidus end
|
|
|
2329 |
|
|
|
2330 |
/*
|
|
|
2331 |
#函式說明:
|
| 226 |
liveuser |
2332 |
#將陣列裡的元素內容用特定符號連接在一起變成字串.
|
| 3 |
liveuser |
2333 |
#回傳結果:
|
|
|
2334 |
#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
|
|
|
2335 |
#$result["function"],當前執行的函數.
|
|
|
2336 |
#$result["error"],錯誤訊息陣列.
|
|
|
2337 |
#$result["content"],處理過後的字串.
|
|
|
2338 |
#必填參數:
|
|
|
2339 |
#$conf["inputArray"],字串陣列,要處理的陣列.
|
|
|
2340 |
$conf["inputArray"]=array();
|
|
|
2341 |
#$conf["combineSymbol"],字串,用來連結各元素的符號.
|
|
|
2342 |
$conf["combineSymbol"]=",";
|
|
|
2343 |
#可省略參數:
|
|
|
2344 |
#無.
|
|
|
2345 |
#參考資料:
|
|
|
2346 |
#無.
|
|
|
2347 |
#備註:
|
|
|
2348 |
#無.
|
|
|
2349 |
*/
|
|
|
2350 |
public static function combineElementWithSymbol(&$conf){
|
| 226 |
liveuser |
2351 |
|
| 3 |
liveuser |
2352 |
#初始化要回傳的內容
|
|
|
2353 |
$result=array();
|
|
|
2354 |
|
|
|
2355 |
#取得當前執行的函數名稱
|
|
|
2356 |
$result["function"]=__FUNCTION__;
|
|
|
2357 |
|
|
|
2358 |
#如果 $conf 不為陣列
|
|
|
2359 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2360 |
|
| 3 |
liveuser |
2361 |
#設置執行失敗
|
|
|
2362 |
$result["status"]="false";
|
| 226 |
liveuser |
2363 |
|
| 3 |
liveuser |
2364 |
#設置執行錯誤訊息
|
|
|
2365 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2366 |
|
|
|
2367 |
#如果傳入的參數為 null
|
|
|
2368 |
if($conf==null){
|
| 226 |
liveuser |
2369 |
|
| 3 |
liveuser |
2370 |
#設置執行錯誤訊息
|
|
|
2371 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2372 |
|
| 3 |
liveuser |
2373 |
}#if end
|
|
|
2374 |
|
|
|
2375 |
#回傳結果
|
|
|
2376 |
return $result;
|
| 226 |
liveuser |
2377 |
|
| 3 |
liveuser |
2378 |
}#if end
|
|
|
2379 |
|
|
|
2380 |
#檢查參數
|
|
|
2381 |
#函式說明:
|
|
|
2382 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2383 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2384 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2385 |
#$result["function"],當前執行的函式名稱.
|
|
|
2386 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2387 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2388 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2389 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2390 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2391 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2392 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2393 |
#必填寫的參數:
|
|
|
2394 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2395 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2396 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2397 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("inputArray","combineSymbol");
|
| 226 |
liveuser |
2398 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
2399 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","string");
|
|
|
2400 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2401 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2402 |
#可以省略的參數:
|
|
|
2403 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2404 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2405 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2406 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("wordsLong");
|
| 226 |
liveuser |
2407 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2408 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
2409 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2410 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
2411 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2412 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2413 |
#參考資料來源:
|
|
|
2414 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2415 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2416 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2417 |
|
|
|
2418 |
#如果檢查有誤
|
|
|
2419 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2420 |
|
| 3 |
liveuser |
2421 |
#設置錯誤識別
|
|
|
2422 |
$result["status"]="false";
|
| 226 |
liveuser |
2423 |
|
| 3 |
liveuser |
2424 |
#設置錯誤訊息
|
|
|
2425 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2426 |
|
| 3 |
liveuser |
2427 |
#回傳結果
|
|
|
2428 |
return $result;
|
| 226 |
liveuser |
2429 |
|
| 3 |
liveuser |
2430 |
}#if end
|
| 226 |
liveuser |
2431 |
|
| 3 |
liveuser |
2432 |
#如果檢查不通過
|
|
|
2433 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2434 |
|
| 3 |
liveuser |
2435 |
#設置錯誤識別
|
|
|
2436 |
$result["status"]="false";
|
| 226 |
liveuser |
2437 |
|
| 3 |
liveuser |
2438 |
#設置錯誤訊息
|
|
|
2439 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2440 |
|
| 3 |
liveuser |
2441 |
#回傳結果
|
|
|
2442 |
return $result;
|
| 226 |
liveuser |
2443 |
|
| 3 |
liveuser |
2444 |
}#if end
|
| 226 |
liveuser |
2445 |
|
| 3 |
liveuser |
2446 |
#初始化要回傳的字串
|
|
|
2447 |
$result["content"]="";
|
| 226 |
liveuser |
2448 |
|
| 3 |
liveuser |
2449 |
#針對 $conf["inputArray"] 的每個元素
|
|
|
2450 |
for($i=0;$i<count($conf["inputArray"]);$i++){
|
| 226 |
liveuser |
2451 |
|
| 3 |
liveuser |
2452 |
#如果是第一筆
|
|
|
2453 |
if($i==0){
|
| 226 |
liveuser |
2454 |
|
| 3 |
liveuser |
2455 |
#將字串連接在一塊
|
|
|
2456 |
$result["content"]=$result["content"].$conf["inputArray"][$i];
|
| 226 |
liveuser |
2457 |
|
| 3 |
liveuser |
2458 |
}#if end
|
| 226 |
liveuser |
2459 |
|
| 3 |
liveuser |
2460 |
#反之是最後一筆
|
|
|
2461 |
else{
|
| 226 |
liveuser |
2462 |
|
| 3 |
liveuser |
2463 |
#將字串連接在一塊
|
|
|
2464 |
$result["content"]=$result["content"].$conf["combineSymbol"].$conf["inputArray"][$i];
|
| 226 |
liveuser |
2465 |
|
| 3 |
liveuser |
2466 |
}#else end
|
| 226 |
liveuser |
2467 |
|
| 3 |
liveuser |
2468 |
}#foreach end
|
| 226 |
liveuser |
2469 |
|
| 3 |
liveuser |
2470 |
#執行到這邊代表執行正常
|
|
|
2471 |
$result["status"]="true";
|
| 226 |
liveuser |
2472 |
|
| 3 |
liveuser |
2473 |
#回傳結果
|
|
|
2474 |
return $result;
|
| 226 |
liveuser |
2475 |
|
| 3 |
liveuser |
2476 |
}#function combineElementWithSymbol end
|
|
|
2477 |
|
|
|
2478 |
/*
|
|
|
2479 |
#函式說明:
|
|
|
2480 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
2481 |
#回傳結果:
|
|
|
2482 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 226 |
liveuser |
2483 |
#$result["error"],錯誤訊息陣列.
|
| 3 |
liveuser |
2484 |
#$result["function"],當前執行的函數名稱.
|
|
|
2485 |
#$result["content"],分割好的內容陣列.
|
|
|
2486 |
#$result["length"],unicode字串的長度.
|
|
|
2487 |
#必填參數:
|
|
|
2488 |
#$conf["str"],字串",要分割的字串.
|
|
|
2489 |
$conf["str"]="";
|
|
|
2490 |
#可省略參數:
|
|
|
2491 |
#$conf["length"],整數,分割的長度.
|
|
|
2492 |
#$conf["length"]=1;
|
|
|
2493 |
#參考資料:
|
|
|
2494 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2495 |
#備註:
|
|
|
2496 |
#無.
|
|
|
2497 |
*/
|
|
|
2498 |
public static function str_split_unicode(&$conf){
|
| 226 |
liveuser |
2499 |
|
| 3 |
liveuser |
2500 |
#檢查參數
|
|
|
2501 |
#函式說明:
|
|
|
2502 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2503 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2504 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2505 |
#$result["function"],當前執行的函式名稱.
|
|
|
2506 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2507 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2508 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2509 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2510 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
2511 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2512 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2513 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2514 |
#必填寫的參數:
|
|
|
2515 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2516 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2517 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2518 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("str");
|
|
|
2519 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
2520 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
2521 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2522 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2523 |
#可以省略的參數:
|
|
|
2524 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2525 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
2526 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2527 |
#$conf["canNotBeEmpty"]=array();
|
|
|
2528 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
2529 |
#$conf["canBeEmpty"]=array();
|
|
|
2530 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
2531 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
2532 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2533 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
|
| 226 |
liveuser |
2534 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2535 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("integer");
|
|
|
2536 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2537 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(1);
|
|
|
2538 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2539 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2540 |
#參考資料來源:
|
|
|
2541 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2542 |
#建議:
|
|
|
2543 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
2544 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2545 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
2546 |
|
| 3 |
liveuser |
2547 |
#如果檢查參數失敗
|
|
|
2548 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
2549 |
|
| 3 |
liveuser |
2550 |
#設置執行失敗
|
|
|
2551 |
$result["status"]="false";
|
| 226 |
liveuser |
2552 |
|
| 3 |
liveuser |
2553 |
#設置執行錯誤訊息
|
|
|
2554 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2555 |
|
| 3 |
liveuser |
2556 |
#回傳結果
|
|
|
2557 |
return $result;
|
| 226 |
liveuser |
2558 |
|
|
|
2559 |
}#if end
|
|
|
2560 |
|
| 3 |
liveuser |
2561 |
#如果檢查參數不通過
|
|
|
2562 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
2563 |
|
| 3 |
liveuser |
2564 |
#設置執行失敗
|
|
|
2565 |
$result["status"]="false";
|
| 226 |
liveuser |
2566 |
|
| 3 |
liveuser |
2567 |
#設置執行錯誤訊息
|
|
|
2568 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2569 |
|
| 3 |
liveuser |
2570 |
#回傳結果
|
|
|
2571 |
return $result;
|
| 226 |
liveuser |
2572 |
|
| 3 |
liveuser |
2573 |
}#if end
|
| 226 |
liveuser |
2574 |
|
| 3 |
liveuser |
2575 |
#要分割的長度若小於1
|
|
|
2576 |
if($conf["length"]<1){
|
| 226 |
liveuser |
2577 |
|
| 3 |
liveuser |
2578 |
#設置執行失敗
|
|
|
2579 |
$result["status"]="false";
|
| 226 |
liveuser |
2580 |
|
| 3 |
liveuser |
2581 |
#設置執行錯誤訊息
|
|
|
2582 |
$result["error"][]="參數 \$conf[\"length\"] 不得小於 1";
|
| 226 |
liveuser |
2583 |
|
| 3 |
liveuser |
2584 |
#回傳結果
|
|
|
2585 |
return $result;
|
| 226 |
liveuser |
2586 |
|
| 3 |
liveuser |
2587 |
}#if end
|
| 226 |
liveuser |
2588 |
|
| 3 |
liveuser |
2589 |
#初始化要回傳的字串陣列
|
|
|
2590 |
$result["content"]=array();
|
| 226 |
liveuser |
2591 |
|
| 3 |
liveuser |
2592 |
#取得 $conf["str"] 的長度
|
|
|
2593 |
$result["length"]=mb_strlen($conf["str"],"UTF-8");
|
| 226 |
liveuser |
2594 |
|
| 3 |
liveuser |
2595 |
#依據 $conf["str"] 與 $conf["length"]
|
|
|
2596 |
for($i=0;$i<$result["length"];$i=$i+$conf["length"]){
|
| 226 |
liveuser |
2597 |
|
| 3 |
liveuser |
2598 |
#從位置 $i 往後讀 $conf["length"] 個字,編碼為"UTF-8"
|
|
|
2599 |
$result["content"][]=mb_substr($conf["str"], $i, $conf["length"],"UTF-8");
|
| 226 |
liveuser |
2600 |
|
| 3 |
liveuser |
2601 |
}#for end
|
| 226 |
liveuser |
2602 |
|
| 3 |
liveuser |
2603 |
#設置執行正常
|
| 226 |
liveuser |
2604 |
$result["status"]="true";
|
|
|
2605 |
|
|
|
2606 |
#回傳結果
|
| 3 |
liveuser |
2607 |
return $result;
|
| 226 |
liveuser |
2608 |
|
| 3 |
liveuser |
2609 |
}#function str_split_unicode end
|
|
|
2610 |
|
|
|
2611 |
/*
|
|
|
2612 |
#函式說明:
|
|
|
2613 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
2614 |
#回傳結果:
|
|
|
2615 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2616 |
#$result["error"],錯誤訊息陣列.
|
|
|
2617 |
#$result["warning"],警告訊息鎮列.
|
|
|
2618 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
2619 |
#$result["function"],當前執行的函數名稱.
|
|
|
2620 |
#$result["argu"],使用的參數.
|
|
|
2621 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
2622 |
#$result["content"],處理好的的字串內容.
|
|
|
2623 |
#$result["deleted"],被移除的內容.
|
|
|
2624 |
#必填參數:
|
|
|
2625 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
2626 |
$conf["stringIn"]="";
|
|
|
2627 |
#$conf["keyWord"],字串,特定字串.
|
|
|
2628 |
$conf["keyWord"]="";
|
|
|
2629 |
#可省略參數:
|
|
|
2630 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
2631 |
#$conf["recursive"]="true";
|
|
|
2632 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
|
|
|
2633 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
2634 |
#參考資料:
|
|
|
2635 |
#無.
|
|
|
2636 |
#備註:
|
|
|
2637 |
#無.
|
|
|
2638 |
*/
|
|
|
2639 |
public static function delStrBeforeKeyWord(&$conf){
|
| 226 |
liveuser |
2640 |
|
| 3 |
liveuser |
2641 |
#初始化要回傳的內容
|
|
|
2642 |
$result=array();
|
|
|
2643 |
|
|
|
2644 |
#取得當前執行的函數名稱
|
|
|
2645 |
$result["function"]=__FUNCTION__;
|
|
|
2646 |
|
|
|
2647 |
#如果 $conf 不為陣列
|
|
|
2648 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2649 |
|
| 3 |
liveuser |
2650 |
#設置執行失敗
|
|
|
2651 |
$result["status"]="false";
|
| 226 |
liveuser |
2652 |
|
| 3 |
liveuser |
2653 |
#設置執行錯誤訊息
|
|
|
2654 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2655 |
|
|
|
2656 |
#如果傳入的參數為 null
|
|
|
2657 |
if($conf==null){
|
| 226 |
liveuser |
2658 |
|
| 3 |
liveuser |
2659 |
#設置執行錯誤訊息
|
|
|
2660 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2661 |
|
| 3 |
liveuser |
2662 |
}#if end
|
|
|
2663 |
|
|
|
2664 |
#回傳結果
|
|
|
2665 |
return $result;
|
| 226 |
liveuser |
2666 |
|
| 3 |
liveuser |
2667 |
}#if end
|
|
|
2668 |
|
|
|
2669 |
#取得參數
|
|
|
2670 |
$result["argu"]=$conf;
|
|
|
2671 |
|
|
|
2672 |
#檢查參數
|
|
|
2673 |
#函式說明:
|
|
|
2674 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2675 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2676 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2677 |
#$result["function"],當前執行的函式名稱.
|
|
|
2678 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2679 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2680 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2681 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2682 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2683 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2684 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2685 |
#必填寫的參數:
|
|
|
2686 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2687 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2688 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2689 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","keyWord");
|
| 226 |
liveuser |
2690 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
2691 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
2692 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2693 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2694 |
#可以省略的參數:
|
| 218 |
liveuser |
2695 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2696 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
| 3 |
liveuser |
2697 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2698 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive","lastResult");
|
| 226 |
liveuser |
2699 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2700 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array");
|
|
|
2701 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2702 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null);
|
|
|
2703 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2704 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2705 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
2706 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
2707 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
2708 |
#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array("stringIn");
|
|
|
2709 |
#參考資料來源:
|
|
|
2710 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2711 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2712 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2713 |
|
|
|
2714 |
#如果檢查有誤
|
| 218 |
liveuser |
2715 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
2716 |
|
| 3 |
liveuser |
2717 |
#設置錯誤識別
|
|
|
2718 |
$result["status"]="false";
|
| 226 |
liveuser |
2719 |
|
| 3 |
liveuser |
2720 |
#設置錯誤訊息
|
|
|
2721 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2722 |
|
| 3 |
liveuser |
2723 |
#回傳結果
|
|
|
2724 |
return $result;
|
| 226 |
liveuser |
2725 |
|
| 3 |
liveuser |
2726 |
}#if end
|
| 226 |
liveuser |
2727 |
|
| 3 |
liveuser |
2728 |
#如果檢查不通過
|
| 218 |
liveuser |
2729 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
2730 |
|
| 3 |
liveuser |
2731 |
#設置錯誤識別
|
|
|
2732 |
$result["status"]="false";
|
| 226 |
liveuser |
2733 |
|
| 3 |
liveuser |
2734 |
#設置錯誤訊息
|
|
|
2735 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2736 |
|
| 3 |
liveuser |
2737 |
#回傳結果
|
|
|
2738 |
return $result;
|
| 226 |
liveuser |
2739 |
|
| 3 |
liveuser |
2740 |
}#if end
|
| 226 |
liveuser |
2741 |
|
| 3 |
liveuser |
2742 |
#如果要處理的字串已經為空了
|
|
|
2743 |
if($conf["stringIn"]===""){
|
| 226 |
liveuser |
2744 |
|
| 3 |
liveuser |
2745 |
#擁有上次執行的結果.
|
|
|
2746 |
if(isset($conf["lastResult"])){
|
| 226 |
liveuser |
2747 |
|
| 3 |
liveuser |
2748 |
#回傳上次結果
|
|
|
2749 |
return $conf["lastResult"];
|
| 226 |
liveuser |
2750 |
|
| 3 |
liveuser |
2751 |
}#if end
|
| 226 |
liveuser |
2752 |
|
| 218 |
liveuser |
2753 |
#如果關鍵字也是空字串
|
|
|
2754 |
if($conf["keyWord"]===""){
|
| 226 |
liveuser |
2755 |
|
| 218 |
liveuser |
2756 |
#設置有找到關鍵字
|
|
|
2757 |
$result["founded"]="true";
|
| 226 |
liveuser |
2758 |
|
| 218 |
liveuser |
2759 |
#初始化儲存原始的字串
|
|
|
2760 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2761 |
|
| 218 |
liveuser |
2762 |
#結果跟原始字串一樣
|
|
|
2763 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
2764 |
|
| 218 |
liveuser |
2765 |
#設置執行正常識別
|
|
|
2766 |
$result["status"]="true";
|
| 226 |
liveuser |
2767 |
|
| 218 |
liveuser |
2768 |
#回傳結果
|
|
|
2769 |
return $result;
|
| 226 |
liveuser |
2770 |
|
| 218 |
liveuser |
2771 |
}#if end
|
| 226 |
liveuser |
2772 |
|
| 218 |
liveuser |
2773 |
#設置執行正常識別
|
| 3 |
liveuser |
2774 |
$result["status"]="true";
|
| 226 |
liveuser |
2775 |
|
| 3 |
liveuser |
2776 |
#設置警告訊息
|
|
|
2777 |
$result["warning"][]="要處理的參數 stringIn 為空,且沒有參數 lastResult 存在";
|
| 226 |
liveuser |
2778 |
|
| 3 |
liveuser |
2779 |
#初始化儲存原始的字串
|
|
|
2780 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2781 |
|
| 3 |
liveuser |
2782 |
#結果跟原始字串一樣
|
|
|
2783 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
2784 |
|
| 3 |
liveuser |
2785 |
#設置沒有找到關鍵字
|
|
|
2786 |
$result["founded"]="false";
|
| 226 |
liveuser |
2787 |
|
| 3 |
liveuser |
2788 |
#回傳結果
|
|
|
2789 |
return $result;
|
| 226 |
liveuser |
2790 |
|
| 3 |
liveuser |
2791 |
}#if end
|
| 226 |
liveuser |
2792 |
|
| 218 |
liveuser |
2793 |
#如果要判斷的輸入為空字串
|
|
|
2794 |
if($conf["stringIn"]===""){
|
| 226 |
liveuser |
2795 |
|
| 218 |
liveuser |
2796 |
#初始化分割好內容
|
|
|
2797 |
$spiltedStringIn=array();
|
| 226 |
liveuser |
2798 |
|
| 218 |
liveuser |
2799 |
}#if end
|
| 226 |
liveuser |
2800 |
|
| 218 |
liveuser |
2801 |
#反之
|
|
|
2802 |
else{
|
| 226 |
liveuser |
2803 |
|
| 218 |
liveuser |
2804 |
#將要處理的字串用unicode編碼來一個個字分割.
|
|
|
2805 |
#函式說明:
|
|
|
2806 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
2807 |
#回傳結果:
|
|
|
2808 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 226 |
liveuser |
2809 |
#$result["error"],錯誤訊息陣列.
|
| 218 |
liveuser |
2810 |
#$result["function"],當前執行的函數名稱.
|
|
|
2811 |
#$result["content"],分割好的內容.
|
|
|
2812 |
#$result["length"],unicode字串的長度.
|
|
|
2813 |
#必填參數:
|
|
|
2814 |
#$conf["str"],字串",要分割的字串.
|
|
|
2815 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["stringIn"];
|
|
|
2816 |
#可省略參數:
|
|
|
2817 |
#$conf["length"],整數,分割的長度.
|
|
|
2818 |
#$conf["length"]=1;
|
|
|
2819 |
#參考資料:
|
|
|
2820 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2821 |
$str_split_unicode=self::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
2822 |
unset($conf["stringProcess::str_split_unicode"]);
|
| 226 |
liveuser |
2823 |
|
| 218 |
liveuser |
2824 |
#如果分割字串失敗
|
|
|
2825 |
if($str_split_unicode["status"]==="false"){
|
| 226 |
liveuser |
2826 |
|
| 218 |
liveuser |
2827 |
#設置錯誤識別
|
|
|
2828 |
$result["status"]="false";
|
| 226 |
liveuser |
2829 |
|
| 218 |
liveuser |
2830 |
#設置錯誤訊息
|
|
|
2831 |
$result["error"]=$str_split_unicode;
|
| 226 |
liveuser |
2832 |
|
| 218 |
liveuser |
2833 |
#回傳結果
|
|
|
2834 |
return $result;
|
| 226 |
liveuser |
2835 |
|
| 218 |
liveuser |
2836 |
}#if end
|
| 226 |
liveuser |
2837 |
|
| 218 |
liveuser |
2838 |
#取得分割好的字串
|
|
|
2839 |
$spiltedStringIn=$str_split_unicode["content"];
|
| 226 |
liveuser |
2840 |
|
|
|
2841 |
}#else
|
|
|
2842 |
|
| 218 |
liveuser |
2843 |
#如果關鍵字為空字串
|
|
|
2844 |
if($conf["keyWord"]===""){
|
| 226 |
liveuser |
2845 |
|
| 218 |
liveuser |
2846 |
#初始化分割好內容
|
|
|
2847 |
$spiltedKeyWord=array();
|
| 226 |
liveuser |
2848 |
|
| 3 |
liveuser |
2849 |
}#if end
|
| 226 |
liveuser |
2850 |
|
| 218 |
liveuser |
2851 |
#反之
|
|
|
2852 |
else{
|
| 226 |
liveuser |
2853 |
|
| 218 |
liveuser |
2854 |
#將要處理的關鍵字用unicode編碼來一個個字分割.
|
|
|
2855 |
#函式說明:
|
|
|
2856 |
#unicode的字串分割,比str_split的支援度高.
|
|
|
2857 |
#回傳結果:
|
|
|
2858 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 226 |
liveuser |
2859 |
#$result["error"],錯誤訊息陣列.
|
| 218 |
liveuser |
2860 |
#$result["function"],當前執行的函數名稱.
|
|
|
2861 |
#$result["content"],分割好的內容.
|
|
|
2862 |
#$result["length"],unicode字串的長度.
|
|
|
2863 |
#必填參數:
|
|
|
2864 |
#$conf["str"],字串",要分割的字串.
|
|
|
2865 |
$conf["stringProcess::str_split_unicode"]["str"]=$conf["keyWord"];
|
|
|
2866 |
#可省略參數:
|
|
|
2867 |
#$conf["length"],整數,分割的長度.
|
|
|
2868 |
#$conf["length"]=1;
|
|
|
2869 |
#參考資料:
|
|
|
2870 |
#http://php.net/manual/en/function.str-split.php
|
|
|
2871 |
$str_split_unicode=self::str_split_unicode($conf["stringProcess::str_split_unicode"]);
|
|
|
2872 |
unset($conf["stringProcess::str_split_unicode"]);
|
| 226 |
liveuser |
2873 |
|
| 218 |
liveuser |
2874 |
#如果分割字串失敗
|
|
|
2875 |
if($str_split_unicode["status"]==="false"){
|
| 226 |
liveuser |
2876 |
|
| 218 |
liveuser |
2877 |
#設置錯誤識別
|
|
|
2878 |
$result["status"]="false";
|
| 226 |
liveuser |
2879 |
|
| 218 |
liveuser |
2880 |
#設置錯誤訊息
|
|
|
2881 |
$result["error"]=$str_split_unicode;
|
| 226 |
liveuser |
2882 |
|
| 218 |
liveuser |
2883 |
#回傳結果
|
|
|
2884 |
return $result;
|
| 226 |
liveuser |
2885 |
|
| 218 |
liveuser |
2886 |
}#if end
|
| 226 |
liveuser |
2887 |
|
| 218 |
liveuser |
2888 |
#取得分割好的字串
|
|
|
2889 |
$spiltedKeyWord=$str_split_unicode["content"];
|
| 226 |
liveuser |
2890 |
|
| 218 |
liveuser |
2891 |
}#else end
|
| 226 |
liveuser |
2892 |
|
| 3 |
liveuser |
2893 |
#如果關鍵字比要處理的字串長
|
|
|
2894 |
if(count($spiltedKeyWord)>count($spiltedStringIn)){
|
| 226 |
liveuser |
2895 |
|
| 3 |
liveuser |
2896 |
#如果有前次的結果
|
|
|
2897 |
if(isset($conf["lastResult"])){
|
| 226 |
liveuser |
2898 |
|
| 3 |
liveuser |
2899 |
#回傳之
|
|
|
2900 |
return $conf["lastResult"];
|
| 226 |
liveuser |
2901 |
|
| 3 |
liveuser |
2902 |
}#if end
|
| 226 |
liveuser |
2903 |
|
| 3 |
liveuser |
2904 |
#設置錯誤識別
|
|
|
2905 |
$result["status"]="true";
|
| 226 |
liveuser |
2906 |
|
| 3 |
liveuser |
2907 |
#設置錯誤訊息
|
|
|
2908 |
$result["warning"][]="變數 keyWord 不應該比變數 stringIn 長";
|
| 226 |
liveuser |
2909 |
|
| 3 |
liveuser |
2910 |
#初始化儲存原始的字串
|
|
|
2911 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2912 |
|
| 3 |
liveuser |
2913 |
#結果跟原始字串一樣
|
|
|
2914 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
2915 |
|
| 3 |
liveuser |
2916 |
#設置沒有找到關鍵字
|
|
|
2917 |
$result["founded"]="false";
|
| 226 |
liveuser |
2918 |
|
| 3 |
liveuser |
2919 |
#回傳結果
|
|
|
2920 |
return $result;
|
| 226 |
liveuser |
2921 |
|
| 3 |
liveuser |
2922 |
}#if end
|
| 226 |
liveuser |
2923 |
|
| 3 |
liveuser |
2924 |
#初始化儲存要移除第幾個字之前的內容(索引從0開始)
|
|
|
2925 |
$delCount=-1;
|
| 226 |
liveuser |
2926 |
|
| 3 |
liveuser |
2927 |
#初始化暫存關鍵字的第幾個字
|
| 218 |
liveuser |
2928 |
$wordCount=0;
|
| 226 |
liveuser |
2929 |
|
| 3 |
liveuser |
2930 |
#無窮迴圈
|
|
|
2931 |
for($i=0;$i<count($spiltedStringIn);$i++){
|
| 226 |
liveuser |
2932 |
|
| 218 |
liveuser |
2933 |
#如果關鍵字不存在
|
|
|
2934 |
if(!isset($spiltedKeyWord[$wordCount])){
|
| 226 |
liveuser |
2935 |
|
| 218 |
liveuser |
2936 |
#debug
|
|
|
2937 |
#var_dump(__LINE__,$spiltedStringIn,$spiltedStringIn[$i]);
|
| 226 |
liveuser |
2938 |
|
| 218 |
liveuser |
2939 |
#跳過
|
|
|
2940 |
continue;
|
| 226 |
liveuser |
2941 |
|
| 218 |
liveuser |
2942 |
}#if end
|
| 226 |
liveuser |
2943 |
|
| 3 |
liveuser |
2944 |
#如果有遇到相符合的字元
|
|
|
2945 |
if($spiltedStringIn[$i]===$spiltedKeyWord[$wordCount]){
|
| 226 |
liveuser |
2946 |
|
| 3 |
liveuser |
2947 |
#換尋找下個字元有無符合
|
|
|
2948 |
$wordCount++;
|
| 226 |
liveuser |
2949 |
|
| 3 |
liveuser |
2950 |
#如果下一個關鍵字字元不存在
|
|
|
2951 |
if(!isset($spiltedKeyWord[$wordCount])){
|
| 226 |
liveuser |
2952 |
|
| 3 |
liveuser |
2953 |
#代表有找到符合條件的關鍵字了
|
|
|
2954 |
$delCount=$i;
|
| 226 |
liveuser |
2955 |
|
| 3 |
liveuser |
2956 |
#跳出迴圈
|
|
|
2957 |
break;
|
| 226 |
liveuser |
2958 |
|
| 3 |
liveuser |
2959 |
}#if end
|
| 226 |
liveuser |
2960 |
|
| 3 |
liveuser |
2961 |
}#if end
|
| 226 |
liveuser |
2962 |
|
| 3 |
liveuser |
2963 |
#反之沒有遇到相符合的字元
|
|
|
2964 |
else{
|
| 226 |
liveuser |
2965 |
|
| 3 |
liveuser |
2966 |
#初始化 $j 為 0
|
|
|
2967 |
$wordCount=0;
|
| 226 |
liveuser |
2968 |
|
| 3 |
liveuser |
2969 |
}#else end
|
| 226 |
liveuser |
2970 |
|
| 3 |
liveuser |
2971 |
}#for end
|
| 226 |
liveuser |
2972 |
|
| 3 |
liveuser |
2973 |
#初始化儲存原始的字串
|
|
|
2974 |
$result["oriStr"]=$conf["stringIn"];
|
| 226 |
liveuser |
2975 |
|
| 3 |
liveuser |
2976 |
#初始化處理好的字串
|
|
|
2977 |
$result["content"]="";
|
|
|
2978 |
|
|
|
2979 |
#如果有要剔除的字
|
|
|
2980 |
if($delCount>-1){
|
|
|
2981 |
|
|
|
2982 |
#初始化移除的內容
|
|
|
2983 |
$result["deleted"]="";
|
|
|
2984 |
|
|
|
2985 |
#取得剩下的內容
|
|
|
2986 |
for($i=0;$i<$delCount+1;$i++){
|
| 226 |
liveuser |
2987 |
|
| 3 |
liveuser |
2988 |
#逐字取得字串
|
|
|
2989 |
$result["deleted"]=$result["deleted"].$spiltedStringIn[$i];
|
| 226 |
liveuser |
2990 |
|
| 3 |
liveuser |
2991 |
}#for end
|
|
|
2992 |
|
|
|
2993 |
#取得剩下的內容
|
|
|
2994 |
for($i=$delCount+1;$i<count($spiltedStringIn);$i++){
|
| 226 |
liveuser |
2995 |
|
| 3 |
liveuser |
2996 |
#逐字取得字串
|
|
|
2997 |
$result["content"]=$result["content"].$spiltedStringIn[$i];
|
| 226 |
liveuser |
2998 |
|
| 3 |
liveuser |
2999 |
}#for end
|
| 226 |
liveuser |
3000 |
|
| 3 |
liveuser |
3001 |
#設置有找到關鍵字串
|
|
|
3002 |
$result["founded"]="true";
|
| 226 |
liveuser |
3003 |
|
| 3 |
liveuser |
3004 |
}#if end
|
| 226 |
liveuser |
3005 |
|
| 3 |
liveuser |
3006 |
#反之沒有要處理的字串
|
|
|
3007 |
else{
|
| 226 |
liveuser |
3008 |
|
| 3 |
liveuser |
3009 |
#取得原始字串
|
|
|
3010 |
$result["content"]=$result["oriStr"];
|
| 226 |
liveuser |
3011 |
|
| 3 |
liveuser |
3012 |
#設置沒有找到關鍵字串
|
|
|
3013 |
$result["founded"]="false";
|
| 226 |
liveuser |
3014 |
|
| 3 |
liveuser |
3015 |
}#else end
|
| 226 |
liveuser |
3016 |
|
| 3 |
liveuser |
3017 |
#設置執行正常
|
|
|
3018 |
$result["status"]="true";
|
| 226 |
liveuser |
3019 |
|
| 3 |
liveuser |
3020 |
#如果需要遞迴執行
|
|
|
3021 |
if($conf["recursive"]==="true"){
|
| 226 |
liveuser |
3022 |
|
| 3 |
liveuser |
3023 |
#如果沒有找到目標
|
|
|
3024 |
if($result["founded"]==="false"){
|
| 226 |
liveuser |
3025 |
|
| 3 |
liveuser |
3026 |
#如果有前次的結果
|
|
|
3027 |
if(isset($conf["lastResult"])){
|
| 226 |
liveuser |
3028 |
|
| 3 |
liveuser |
3029 |
#回傳之
|
|
|
3030 |
return $conf["lastResult"];
|
| 226 |
liveuser |
3031 |
|
| 3 |
liveuser |
3032 |
}#if enb
|
| 226 |
liveuser |
3033 |
|
| 3 |
liveuser |
3034 |
#回傳本次結果
|
|
|
3035 |
return $result;
|
| 226 |
liveuser |
3036 |
|
| 3 |
liveuser |
3037 |
}#if end
|
| 226 |
liveuser |
3038 |
|
| 3 |
liveuser |
3039 |
#函式說明:
|
|
|
3040 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3041 |
#回傳結果:
|
|
|
3042 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3043 |
#$result["error"],錯誤訊息陣列.
|
|
|
3044 |
#$result["warning"],警告訊息鎮列.
|
|
|
3045 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3046 |
#$result["function"],當前執行的函數名稱.
|
|
|
3047 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
3048 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
3049 |
#必填參數:
|
|
|
3050 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3051 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$result["content"];
|
|
|
3052 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3053 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$conf["keyWord"];
|
|
|
3054 |
#可省略參數:
|
|
|
3055 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
3056 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
|
|
3057 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.
|
|
|
3058 |
$conf["stringProcess::delStrBeforeKeyWord"]["lastResult"]=$result;
|
|
|
3059 |
#參考資料:
|
|
|
3060 |
#無.
|
|
|
3061 |
#備註:
|
|
|
3062 |
#無.
|
|
|
3063 |
return stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3064 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3065 |
|
| 3 |
liveuser |
3066 |
}#if end
|
| 226 |
liveuser |
3067 |
|
| 3 |
liveuser |
3068 |
#回傳結果
|
|
|
3069 |
return $result;
|
| 226 |
liveuser |
3070 |
|
| 3 |
liveuser |
3071 |
}#function delStrBeforeKeyWord end
|
|
|
3072 |
|
|
|
3073 |
/*
|
|
|
3074 |
#函式說明:
|
|
|
3075 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
3076 |
#回傳結果:
|
|
|
3077 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3078 |
#$result["error"],錯誤訊息陣列.
|
|
|
3079 |
#$result["warning"],警告訊息鎮列.
|
|
|
3080 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3081 |
#$result["function"],當前執行的函數名稱.
|
|
|
3082 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3083 |
#$result["content"],處理好的的字串內容.
|
|
|
3084 |
#$result["deleted"],被移除的內容.
|
|
|
3085 |
#$result["argu"],使用的參數.
|
|
|
3086 |
#必填參數:
|
|
|
3087 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3088 |
$conf["stringIn"]="";
|
|
|
3089 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3090 |
$conf["keyWord"]="";
|
|
|
3091 |
#可省略參數:
|
|
|
3092 |
#$conf["deleteLastRepeatedOne"],字串,預設為"false";若為"true"則代表連續遇到同 $conf["keyWord"] 的內容,要將移除內容的起點往後移動到為後一個 $conf["keyWord"].
|
|
|
3093 |
#$conf["deleteLastRepeatedOne"]="";
|
|
|
3094 |
#參考資料:
|
|
|
3095 |
#無.
|
|
|
3096 |
#備註:
|
|
|
3097 |
#無.
|
|
|
3098 |
*/
|
|
|
3099 |
public static function delStrAfterKeyWord(&$conf){
|
| 226 |
liveuser |
3100 |
|
| 3 |
liveuser |
3101 |
#初始化要回傳的內容
|
|
|
3102 |
$result=array();
|
|
|
3103 |
|
|
|
3104 |
#取得當前執行的函數名稱
|
|
|
3105 |
$result["function"]=__FUNCTION__;
|
|
|
3106 |
|
|
|
3107 |
#如果 $conf 不為陣列
|
|
|
3108 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
3109 |
|
| 3 |
liveuser |
3110 |
#設置執行失敗
|
|
|
3111 |
$result["status"]="false";
|
| 226 |
liveuser |
3112 |
|
| 3 |
liveuser |
3113 |
#設置執行錯誤訊息
|
|
|
3114 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3115 |
|
|
|
3116 |
#如果傳入的參數為 null
|
|
|
3117 |
if($conf==null){
|
| 226 |
liveuser |
3118 |
|
| 3 |
liveuser |
3119 |
#設置執行錯誤訊息
|
|
|
3120 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3121 |
|
| 3 |
liveuser |
3122 |
}#if end
|
|
|
3123 |
|
|
|
3124 |
#回傳結果
|
|
|
3125 |
return $result;
|
| 226 |
liveuser |
3126 |
|
| 3 |
liveuser |
3127 |
}#if end
|
|
|
3128 |
|
|
|
3129 |
#檢查參數
|
|
|
3130 |
#函式說明:
|
|
|
3131 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3132 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3133 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3134 |
#$result["function"],當前執行的函式名稱.
|
|
|
3135 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3136 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3137 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3138 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3139 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3140 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3141 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3142 |
#必填寫的參數:
|
|
|
3143 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3144 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3145 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3146 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("stringIn","keyWord");
|
| 226 |
liveuser |
3147 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
3148 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3149 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3150 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3151 |
#可以省略的參數:
|
|
|
3152 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3153 |
#$conf["canBeEmptyString"]="false";
|
|
|
3154 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3155 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("deleteLastRepeatedOne");
|
| 226 |
liveuser |
3156 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
3157 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
3158 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3159 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
3160 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3161 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3162 |
#參考資料來源:
|
|
|
3163 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3164 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3165 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3166 |
|
|
|
3167 |
#如果檢查有誤
|
|
|
3168 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
3169 |
|
| 3 |
liveuser |
3170 |
#設置錯誤識別
|
|
|
3171 |
$result["status"]="false";
|
| 226 |
liveuser |
3172 |
|
| 3 |
liveuser |
3173 |
#設置錯誤訊息
|
|
|
3174 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3175 |
|
| 3 |
liveuser |
3176 |
#回傳結果
|
|
|
3177 |
return $result;
|
| 226 |
liveuser |
3178 |
|
| 3 |
liveuser |
3179 |
}#if end
|
| 226 |
liveuser |
3180 |
|
| 3 |
liveuser |
3181 |
#如果檢查不通過
|
|
|
3182 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
3183 |
|
| 3 |
liveuser |
3184 |
#設置錯誤識別
|
|
|
3185 |
$result["status"]="false";
|
| 226 |
liveuser |
3186 |
|
| 3 |
liveuser |
3187 |
#設置錯誤訊息
|
|
|
3188 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3189 |
|
| 3 |
liveuser |
3190 |
#回傳結果
|
|
|
3191 |
return $result;
|
| 226 |
liveuser |
3192 |
|
| 3 |
liveuser |
3193 |
}#if end
|
| 226 |
liveuser |
3194 |
|
| 3 |
liveuser |
3195 |
#記錄使用的參數
|
|
|
3196 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
3197 |
|
| 3 |
liveuser |
3198 |
#倒序內容
|
|
|
3199 |
$conf["stringIn"]=strrev($conf["stringIn"]);
|
| 226 |
liveuser |
3200 |
|
| 3 |
liveuser |
3201 |
#倒敘關鍵字
|
|
|
3202 |
$conf["keyWord"]=strrev($conf["keyWord"]);
|
| 226 |
liveuser |
3203 |
|
| 3 |
liveuser |
3204 |
#函式說明:
|
|
|
3205 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3206 |
#回傳結果:
|
|
|
3207 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3208 |
#$result["error"],錯誤訊息陣列.
|
|
|
3209 |
#$result["warning"],警告訊息鎮列.
|
|
|
3210 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3211 |
#$result["function"],當前執行的函數名稱.
|
|
|
3212 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
3213 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
3214 |
#必填參數:
|
|
|
3215 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3216 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["stringIn"];
|
|
|
3217 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3218 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$conf["keyWord"];
|
|
|
3219 |
#可省略參數:
|
| 226 |
liveuser |
3220 |
|
| 3 |
liveuser |
3221 |
#如果不需要移除最後一個符合的關鍵字之後的內容
|
|
|
3222 |
if($conf["deleteLastRepeatedOne"]==="false"){
|
| 226 |
liveuser |
3223 |
|
| 3 |
liveuser |
3224 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
3225 |
$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
|
| 226 |
liveuser |
3226 |
|
| 3 |
liveuser |
3227 |
}#if end
|
| 226 |
liveuser |
3228 |
|
| 3 |
liveuser |
3229 |
#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則回改回傳該內容.
|
|
|
3230 |
#$conf["lastResult"]=$delStrBeforeKeyWord;
|
|
|
3231 |
#參考資料:
|
|
|
3232 |
#無.
|
|
|
3233 |
#備註:
|
|
|
3234 |
#無.
|
|
|
3235 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3236 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3237 |
|
| 3 |
liveuser |
3238 |
#如果執行失敗
|
|
|
3239 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
3240 |
|
| 3 |
liveuser |
3241 |
#設置錯誤識別
|
|
|
3242 |
$result["status"]="false";
|
| 226 |
liveuser |
3243 |
|
| 3 |
liveuser |
3244 |
#設置錯誤訊息
|
|
|
3245 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
3246 |
|
| 3 |
liveuser |
3247 |
#回傳結果
|
|
|
3248 |
return $result;
|
| 226 |
liveuser |
3249 |
|
| 3 |
liveuser |
3250 |
}#if end
|
| 226 |
liveuser |
3251 |
|
| 3 |
liveuser |
3252 |
#如果沒有關鍵字
|
|
|
3253 |
if($delStrBeforeKeyWord["founded"]==="false"){
|
| 226 |
liveuser |
3254 |
|
| 3 |
liveuser |
3255 |
#設置執行正常
|
|
|
3256 |
$result["status"]="true";
|
| 226 |
liveuser |
3257 |
|
| 3 |
liveuser |
3258 |
#設置沒有找到關鍵字
|
|
|
3259 |
$result["founded"]="false";
|
| 226 |
liveuser |
3260 |
|
| 3 |
liveuser |
3261 |
#初始化儲存原始的字串
|
|
|
3262 |
$result["oriStr"]=strrev($delStrBeforeKeyWord["oriStr"]);
|
| 226 |
liveuser |
3263 |
|
| 3 |
liveuser |
3264 |
#取得移除後的結果
|
|
|
3265 |
$result["content"]=strrev($delStrBeforeKeyWord["content"]);
|
| 226 |
liveuser |
3266 |
|
| 3 |
liveuser |
3267 |
#回傳結果
|
|
|
3268 |
return $result;
|
| 226 |
liveuser |
3269 |
|
| 3 |
liveuser |
3270 |
}#if end
|
| 226 |
liveuser |
3271 |
|
| 3 |
liveuser |
3272 |
#設置執行正常
|
|
|
3273 |
$result["status"]="true";
|
| 226 |
liveuser |
3274 |
|
| 3 |
liveuser |
3275 |
#設置有找到關鍵字
|
|
|
3276 |
$result["founded"]="true";
|
| 226 |
liveuser |
3277 |
|
| 3 |
liveuser |
3278 |
#初始化儲存原始的字串
|
|
|
3279 |
$result["oriStr"]=strrev($conf["stringIn"]);
|
| 226 |
liveuser |
3280 |
|
| 3 |
liveuser |
3281 |
#取得移除後的結果
|
|
|
3282 |
$result["content"]=strrev($delStrBeforeKeyWord["content"]);
|
| 226 |
liveuser |
3283 |
|
| 3 |
liveuser |
3284 |
#取得被移除的內容
|
|
|
3285 |
$result["deleted"]=strrev($delStrBeforeKeyWord["deleted"]);
|
| 226 |
liveuser |
3286 |
|
| 3 |
liveuser |
3287 |
#回傳結果
|
|
|
3288 |
return $result;
|
| 226 |
liveuser |
3289 |
|
| 3 |
liveuser |
3290 |
}#function delStrAfterKeyWord end
|
|
|
3291 |
|
|
|
3292 |
/*
|
|
|
3293 |
#函式說明:
|
|
|
3294 |
#移除多個字串開頭相同的部分
|
|
|
3295 |
#回傳結果:
|
|
|
3296 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3297 |
#$result["error"],錯誤訊息陣列.
|
|
|
3298 |
#$result["function"],當前執行的函數名稱.
|
|
|
3299 |
#$result["content"],處理好的的字串內容.
|
|
|
3300 |
#必填參數:
|
|
|
3301 |
#$conf["strIn"],字串陣列,每個要處理的字串.
|
| 226 |
liveuser |
3302 |
$conf["strIn"]=array();
|
| 3 |
liveuser |
3303 |
#可省略參數:
|
|
|
3304 |
#無.
|
|
|
3305 |
#參考資料:
|
|
|
3306 |
#無.
|
|
|
3307 |
#備註:
|
|
|
3308 |
#無.
|
|
|
3309 |
*/
|
|
|
3310 |
public static function delSameHead(&$conf){
|
| 226 |
liveuser |
3311 |
|
| 3 |
liveuser |
3312 |
#初始化要回傳的內容
|
|
|
3313 |
$result=array();
|
|
|
3314 |
|
|
|
3315 |
#取得當前執行的函數名稱
|
|
|
3316 |
$result["function"]=__FUNCTION__;
|
|
|
3317 |
|
|
|
3318 |
#如果 $conf 不為陣列
|
|
|
3319 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
3320 |
|
| 3 |
liveuser |
3321 |
#設置執行失敗
|
|
|
3322 |
$result["status"]="false";
|
| 226 |
liveuser |
3323 |
|
| 3 |
liveuser |
3324 |
#設置執行錯誤訊息
|
|
|
3325 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3326 |
|
|
|
3327 |
#如果傳入的參數為 null
|
|
|
3328 |
if($conf==null){
|
| 226 |
liveuser |
3329 |
|
| 3 |
liveuser |
3330 |
#設置執行錯誤訊息
|
|
|
3331 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3332 |
|
| 3 |
liveuser |
3333 |
}#if end
|
|
|
3334 |
|
|
|
3335 |
#回傳結果
|
|
|
3336 |
return $result;
|
| 226 |
liveuser |
3337 |
|
| 3 |
liveuser |
3338 |
}#if end
|
| 226 |
liveuser |
3339 |
|
| 3 |
liveuser |
3340 |
#函式說明:
|
|
|
3341 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3342 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3343 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3344 |
#$result["function"],當前執行的函式名稱.
|
|
|
3345 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3346 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3347 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3348 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3349 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3350 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3351 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3352 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3353 |
#必填寫的參數:
|
|
|
3354 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3355 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3356 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3357 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("strIn");
|
|
|
3358 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3359 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
|
|
|
3360 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3361 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3362 |
#可以省略的參數:
|
|
|
3363 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3364 |
#$conf["canBeEmptyString"]="false";
|
|
|
3365 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
3366 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3367 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3368 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
3369 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
3370 |
#$conf["skipableVariableType"]=array();
|
|
|
3371 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3372 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
3373 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3374 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3375 |
#參考資料來源:
|
|
|
3376 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3377 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
3378 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
3379 |
|
| 3 |
liveuser |
3380 |
#初始化儲存開頭相同的字串
|
| 226 |
liveuser |
3381 |
$sameHeadStr="";
|
|
|
3382 |
|
|
|
3383 |
#$conf["strIn"]的第一個元素有幾個字就執行幾次
|
| 3 |
liveuser |
3384 |
for($i=0;$i<strlen($conf["strIn"][0]);$i++){
|
| 226 |
liveuser |
3385 |
|
| 3 |
liveuser |
3386 |
#取得當前可能相同的開頭字串
|
|
|
3387 |
$keyWordPart=$sameHeadStr.$conf["strIn"][0][$i];
|
| 226 |
liveuser |
3388 |
|
| 3 |
liveuser |
3389 |
#函式說明:
|
|
|
3390 |
#取得多個符合特定字首與字尾的字串.
|
|
|
3391 |
#回傳結果:
|
|
|
3392 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
3393 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
3394 |
#$result["function"],當前執行的函數名稱.
|
|
|
3395 |
#$result["returnString"],爲符合字首條件的字串陣列內容。
|
|
|
3396 |
#必填參數:
|
|
|
3397 |
#$conf["checkString"],陣列字串,要檢查的字串們.
|
|
|
3398 |
$conf["search::getMeetConditionsStringMulti"]["checkString"]=$conf["strIn"];#要檢查的字串陣列
|
|
|
3399 |
#可省略參數:
|
|
|
3400 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
3401 |
$conf["search::getMeetConditionsStringMulti"]["frontWord"]=$keyWordPart;
|
|
|
3402 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
3403 |
#$conf["tailWord"]="";
|
|
|
3404 |
#參考資料:
|
|
|
3405 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
3406 |
$checkResult=search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]);
|
|
|
3407 |
unset($conf["search::getMeetConditionsStringMulti"]);
|
| 226 |
liveuser |
3408 |
|
| 3 |
liveuser |
3409 |
#如果執行失敗
|
|
|
3410 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
3411 |
|
| 3 |
liveuser |
3412 |
#設置執行失敗
|
|
|
3413 |
$result["status"]="false";
|
| 226 |
liveuser |
3414 |
|
| 3 |
liveuser |
3415 |
#設置執行錯誤訊息
|
|
|
3416 |
$result["error"]=$checkResult;
|
|
|
3417 |
|
|
|
3418 |
#回傳結果
|
|
|
3419 |
return $result;
|
| 226 |
liveuser |
3420 |
|
| 3 |
liveuser |
3421 |
}#if end
|
| 226 |
liveuser |
3422 |
|
| 3 |
liveuser |
3423 |
#如果有找到相同的開頭
|
|
|
3424 |
if($checkResult["founded"]=="true"){
|
| 226 |
liveuser |
3425 |
|
| 3 |
liveuser |
3426 |
#取得新的開頭相同字串內容
|
|
|
3427 |
$sameHeadStr=$keyWordPart;
|
| 226 |
liveuser |
3428 |
|
| 3 |
liveuser |
3429 |
}#if end
|
| 226 |
liveuser |
3430 |
|
| 3 |
liveuser |
3431 |
#反之
|
|
|
3432 |
else{
|
| 226 |
liveuser |
3433 |
|
| 3 |
liveuser |
3434 |
#跳出迴圈
|
|
|
3435 |
break;
|
| 226 |
liveuser |
3436 |
|
| 3 |
liveuser |
3437 |
}#else end
|
| 226 |
liveuser |
3438 |
|
| 3 |
liveuser |
3439 |
}#for end
|
| 226 |
liveuser |
3440 |
|
|
|
3441 |
#$conf["strIn"]有幾個元素就執行幾次
|
| 3 |
liveuser |
3442 |
for($i=0;$i<count($conf["strIn"]);$i++){
|
| 226 |
liveuser |
3443 |
|
| 3 |
liveuser |
3444 |
#移除 $conf["strIn"] 中每個字串開頭相同的部分
|
|
|
3445 |
#函式說明:
|
|
|
3446 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3447 |
#回傳結果:
|
|
|
3448 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3449 |
#$result["error"],錯誤訊息陣列.
|
|
|
3450 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3451 |
#$result["function"],當前執行的函數名稱.
|
|
|
3452 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3453 |
#$result["content"],處理好的的字串內容.
|
|
|
3454 |
#必填參數:
|
|
|
3455 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["strIn"][$i];#要處理的字串.
|
|
|
3456 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$sameHeadStr;#特定字串.
|
|
|
3457 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3458 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3459 |
|
| 3 |
liveuser |
3460 |
#如果執行失敗
|
|
|
3461 |
if($delStrBeforeKeyWord["status"]=="false"){
|
| 226 |
liveuser |
3462 |
|
| 3 |
liveuser |
3463 |
#設置執行失敗
|
|
|
3464 |
$result["status"]="false";
|
| 226 |
liveuser |
3465 |
|
| 3 |
liveuser |
3466 |
#設置執行錯誤訊息
|
|
|
3467 |
$result["error"]=$delStrBeforeKeyWord;
|
|
|
3468 |
|
|
|
3469 |
#回傳結果
|
|
|
3470 |
return $result;
|
| 226 |
liveuser |
3471 |
|
| 3 |
liveuser |
3472 |
}#if end
|
| 226 |
liveuser |
3473 |
|
|
|
3474 |
#取得處理好的字串
|
| 3 |
liveuser |
3475 |
$result["content"][]=$delStrBeforeKeyWord["content"];
|
| 226 |
liveuser |
3476 |
|
| 3 |
liveuser |
3477 |
}#for end
|
| 226 |
liveuser |
3478 |
|
| 3 |
liveuser |
3479 |
#設置執行正常
|
|
|
3480 |
$result["status"]="true";
|
| 226 |
liveuser |
3481 |
|
| 3 |
liveuser |
3482 |
#回傳結果
|
|
|
3483 |
return $result;
|
| 226 |
liveuser |
3484 |
|
| 3 |
liveuser |
3485 |
}#function delSameHead end
|
| 226 |
liveuser |
3486 |
|
| 3 |
liveuser |
3487 |
/*
|
|
|
3488 |
#函式說明:
|
|
|
3489 |
#移除字串開頭的特定內容
|
|
|
3490 |
#回傳結果:
|
|
|
3491 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
3492 |
#$result["error"],錯誤訊息陣列.
|
|
|
3493 |
#$result["function"],當前執行的函數.
|
|
|
3494 |
#$result["content"],處理好的字串.
|
|
|
3495 |
#$result["argu"],使用的參數.
|
|
|
3496 |
#必填參數:
|
|
|
3497 |
#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
|
|
|
3498 |
$conf["inputStr"]="";
|
|
|
3499 |
#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
|
| 226 |
liveuser |
3500 |
$conf["keyWord"]="";
|
| 3 |
liveuser |
3501 |
#可省略參數:
|
|
|
3502 |
#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
|
|
|
3503 |
#$conf["recursive"]="false";
|
|
|
3504 |
#參考資料:
|
|
|
3505 |
#無.
|
|
|
3506 |
#備註:
|
|
|
3507 |
#無.
|
|
|
3508 |
*/
|
|
|
3509 |
public static function delKeyWordsInStrHead(&$conf){
|
| 226 |
liveuser |
3510 |
|
| 3 |
liveuser |
3511 |
#初始化要回傳的結果
|
|
|
3512 |
$result=array();
|
|
|
3513 |
|
|
|
3514 |
#初始化要回傳的結果
|
|
|
3515 |
$result["content"]="";
|
|
|
3516 |
|
|
|
3517 |
#儲存當前執行的函數
|
|
|
3518 |
$result["function"]=__FUNCTION__;
|
|
|
3519 |
|
|
|
3520 |
#如果 $conf 不為陣列
|
|
|
3521 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
3522 |
|
| 3 |
liveuser |
3523 |
#設置執行失敗
|
|
|
3524 |
$result["status"]="false";
|
| 226 |
liveuser |
3525 |
|
| 3 |
liveuser |
3526 |
#設置執行錯誤訊息
|
|
|
3527 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3528 |
|
|
|
3529 |
#如果傳入的參數為 null
|
|
|
3530 |
if($conf==null){
|
| 226 |
liveuser |
3531 |
|
| 3 |
liveuser |
3532 |
#設置執行錯誤訊息
|
|
|
3533 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3534 |
|
| 3 |
liveuser |
3535 |
}#if end
|
|
|
3536 |
|
|
|
3537 |
#回傳結果
|
|
|
3538 |
return $result;
|
| 226 |
liveuser |
3539 |
|
| 3 |
liveuser |
3540 |
}#if end
|
| 226 |
liveuser |
3541 |
|
| 3 |
liveuser |
3542 |
#記錄參數
|
|
|
3543 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
3544 |
|
| 3 |
liveuser |
3545 |
#檢查參數
|
|
|
3546 |
#函式說明:
|
|
|
3547 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3548 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3549 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3550 |
#$result["function"],當前執行的函式名稱.
|
|
|
3551 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3552 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3553 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3554 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3555 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3556 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3557 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3558 |
#必填寫的參數:
|
|
|
3559 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3560 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3561 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3562 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("inputStr","keyWord");
|
| 226 |
liveuser |
3563 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
3564 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
3565 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3566 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3567 |
#可以省略的參數:
|
|
|
3568 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
3569 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3570 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3571 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("recursive");
|
| 226 |
liveuser |
3572 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
3573 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
3574 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3575 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
3576 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3577 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("subject","plainBody","htmlBody","receiverMail","receiverMailDisplay","receiverNameDisplay");
|
|
|
3578 |
#參考資料來源:
|
|
|
3579 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3580 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3581 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
3582 |
|
| 3 |
liveuser |
3583 |
#如果檢查失敗
|
|
|
3584 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
3585 |
|
| 3 |
liveuser |
3586 |
#設置錯誤識別
|
|
|
3587 |
$result["status"]="false";
|
| 226 |
liveuser |
3588 |
|
| 3 |
liveuser |
3589 |
#設置錯誤訊息
|
|
|
3590 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3591 |
|
| 3 |
liveuser |
3592 |
#回傳結果
|
|
|
3593 |
return $result;
|
| 226 |
liveuser |
3594 |
|
| 3 |
liveuser |
3595 |
}#if end
|
| 226 |
liveuser |
3596 |
|
| 3 |
liveuser |
3597 |
#如果檢查不通過
|
|
|
3598 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
3599 |
|
| 3 |
liveuser |
3600 |
#設置錯誤識別
|
|
|
3601 |
$result["status"]="false";
|
| 226 |
liveuser |
3602 |
|
| 3 |
liveuser |
3603 |
#設置錯誤訊息
|
|
|
3604 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3605 |
|
| 3 |
liveuser |
3606 |
#回傳結果
|
|
|
3607 |
return $result;
|
| 226 |
liveuser |
3608 |
|
| 3 |
liveuser |
3609 |
}#if end
|
| 226 |
liveuser |
3610 |
|
| 3 |
liveuser |
3611 |
#取得關鍵字的位置
|
|
|
3612 |
$found=strpos($conf["inputStr"],$conf["keyWord"]);
|
| 226 |
liveuser |
3613 |
|
| 3 |
liveuser |
3614 |
#debug
|
|
|
3615 |
#var_dump($conf["inputStr"],$conf["keyWord"],$found);
|
| 226 |
liveuser |
3616 |
|
| 3 |
liveuser |
3617 |
#如果沒有找到關鍵字
|
|
|
3618 |
if($found===false){
|
| 226 |
liveuser |
3619 |
|
| 3 |
liveuser |
3620 |
#設置執行正常
|
|
|
3621 |
$result["status"]="true";
|
| 226 |
liveuser |
3622 |
|
| 3 |
liveuser |
3623 |
#設置處理好的字串
|
|
|
3624 |
$result["content"]=$conf["inputStr"];
|
| 226 |
liveuser |
3625 |
|
| 3 |
liveuser |
3626 |
#回傳結果
|
|
|
3627 |
return $result;
|
| 226 |
liveuser |
3628 |
|
| 3 |
liveuser |
3629 |
}#if end
|
| 226 |
liveuser |
3630 |
|
| 3 |
liveuser |
3631 |
#如果關鍵字在開頭
|
|
|
3632 |
else if($found===0){
|
| 226 |
liveuser |
3633 |
|
| 3 |
liveuser |
3634 |
#分割字串
|
|
|
3635 |
$spiledStr=str_split($conf["inputStr"]);
|
| 226 |
liveuser |
3636 |
|
| 3 |
liveuser |
3637 |
#執行 count($spiledStr)-2 次迴圈
|
|
|
3638 |
for($i=strlen($conf["keyWord"]);$i<count($spiledStr);$i++){
|
| 226 |
liveuser |
3639 |
|
| 3 |
liveuser |
3640 |
#串接字
|
|
|
3641 |
$result["content"]=$result["content"].$spiledStr[$i];
|
| 226 |
liveuser |
3642 |
|
| 3 |
liveuser |
3643 |
}#for end
|
| 226 |
liveuser |
3644 |
|
| 3 |
liveuser |
3645 |
#設置執行正常
|
|
|
3646 |
$result["status"]="true";
|
| 226 |
liveuser |
3647 |
|
| 3 |
liveuser |
3648 |
#如果有開啟遞迴
|
|
|
3649 |
if($conf["recursive"]==="true"){
|
| 226 |
liveuser |
3650 |
|
| 3 |
liveuser |
3651 |
#函式說明:
|
|
|
3652 |
#移除字串開頭的特定內容
|
|
|
3653 |
#回傳結果:
|
|
|
3654 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
3655 |
#$result["error"],錯誤訊息陣列.
|
|
|
3656 |
#$result["function"],當前執行的函數.
|
|
|
3657 |
#$result["content"],處理好的字串.
|
|
|
3658 |
#必填參數:
|
|
|
3659 |
#$conf["inputStr"],字串,要檢查並移除開頭有 $conf["keyWords"] 的字串.
|
|
|
3660 |
$conf["stringProcess::delKeyWordsInStrHead"]["inputStr"]=$result["content"];
|
|
|
3661 |
#$conf["keyWord"],字串,要移除的字串開頭關鍵字.
|
| 226 |
liveuser |
3662 |
$conf["stringProcess::delKeyWordsInStrHead"]["keyWord"]=$conf["keyWord"];
|
| 3 |
liveuser |
3663 |
#可省略參數:
|
|
|
3664 |
#$conf["recursive"],字串,"true"代表要遞迴移除開頭的關鍵字,預設為"false",只移除開頭關鍵字1次.
|
|
|
3665 |
$conf["stringProcess::delKeyWordsInStrHead"]["recursive"]="true";
|
| 226 |
liveuser |
3666 |
return stringProcess::delKeyWordsInStrHead($conf["stringProcess::delKeyWordsInStrHead"]);
|
|
|
3667 |
unset($conf["stringProcess::delKeyWordsInStrHead"]);
|
|
|
3668 |
|
| 3 |
liveuser |
3669 |
}#if end
|
| 226 |
liveuser |
3670 |
|
| 3 |
liveuser |
3671 |
#回傳結果
|
|
|
3672 |
return $result;
|
| 226 |
liveuser |
3673 |
|
| 3 |
liveuser |
3674 |
}#if end
|
| 226 |
liveuser |
3675 |
|
|
|
3676 |
#反之關鍵字不在開頭
|
| 3 |
liveuser |
3677 |
else{
|
| 226 |
liveuser |
3678 |
|
| 3 |
liveuser |
3679 |
#設置執行正常
|
|
|
3680 |
$result["status"]="true";
|
| 226 |
liveuser |
3681 |
|
| 3 |
liveuser |
3682 |
#設置處理好的字串
|
|
|
3683 |
$result["content"]=$conf["inputStr"];
|
| 226 |
liveuser |
3684 |
|
| 3 |
liveuser |
3685 |
#回傳結果
|
|
|
3686 |
return $result;
|
| 226 |
liveuser |
3687 |
|
| 3 |
liveuser |
3688 |
}#else end
|
| 226 |
liveuser |
3689 |
|
| 3 |
liveuser |
3690 |
#執行到這邊代表不正常
|
| 226 |
liveuser |
3691 |
|
| 3 |
liveuser |
3692 |
#設置錯誤識別
|
|
|
3693 |
$result["status"]="false";
|
| 226 |
liveuser |
3694 |
|
| 3 |
liveuser |
3695 |
#設置錯誤訊息
|
|
|
3696 |
$result["error"][]="非預期的錯誤";
|
| 226 |
liveuser |
3697 |
|
| 3 |
liveuser |
3698 |
#回傳結果
|
|
|
3699 |
return $result;
|
| 226 |
liveuser |
3700 |
|
| 3 |
liveuser |
3701 |
}#function delKeyWordsInStrHead end
|
|
|
3702 |
|
|
|
3703 |
/*
|
|
|
3704 |
#函式說明:
|
|
|
3705 |
#將字串進行解析,取得兩個關鍵字中間的內容.
|
|
|
3706 |
#回傳結果:
|
|
|
3707 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
3708 |
#$result["function"],當前執行的函式內容.
|
|
|
3709 |
#$result["error"],錯誤訊息陣列.
|
|
|
3710 |
#$result["content"],取得的內容.
|
|
|
3711 |
#$result["oriStr"],原始的內容.
|
|
|
3712 |
#$result["found"],是否有找到符合條件的內容.
|
|
|
3713 |
#必填參數:
|
|
|
3714 |
#$conf["input"],字串,要處理的字串.
|
|
|
3715 |
$conf["input"]="";
|
|
|
3716 |
#$conf["startKeyWord"],字串,開頭的關鍵字.
|
|
|
3717 |
$conf["startKeyWord"]="";
|
|
|
3718 |
#$conf["endKeyWord"],字串,結束的關鍵字.
|
|
|
3719 |
$conf["endKeyWord"]="";
|
|
|
3720 |
#可省略參數:
|
|
|
3721 |
#無.
|
|
|
3722 |
#參考資料:
|
|
|
3723 |
#無.
|
|
|
3724 |
#備註:
|
|
|
3725 |
#無.
|
|
|
3726 |
*/
|
|
|
3727 |
public static function getContentBetweenKeyWord(&$conf){
|
| 226 |
liveuser |
3728 |
|
| 3 |
liveuser |
3729 |
#初始化要回傳的結果
|
|
|
3730 |
$result=array();
|
|
|
3731 |
|
|
|
3732 |
#取得當前執行的函數名稱
|
|
|
3733 |
$result["function"]=__FUNCTION__;
|
|
|
3734 |
|
|
|
3735 |
#如果沒有參數
|
|
|
3736 |
if(func_num_args()==0){
|
| 226 |
liveuser |
3737 |
|
| 3 |
liveuser |
3738 |
#設置執行失敗
|
|
|
3739 |
$result["status"]="false";
|
| 226 |
liveuser |
3740 |
|
| 3 |
liveuser |
3741 |
#設置執行錯誤訊息
|
|
|
3742 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
3743 |
|
| 3 |
liveuser |
3744 |
#回傳結果
|
|
|
3745 |
return $result;
|
| 226 |
liveuser |
3746 |
|
| 3 |
liveuser |
3747 |
}#if end
|
|
|
3748 |
|
|
|
3749 |
#取得參數
|
|
|
3750 |
$result["argu"]=$conf;
|
|
|
3751 |
|
|
|
3752 |
#如果 $conf 不為陣列
|
|
|
3753 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
3754 |
|
| 3 |
liveuser |
3755 |
#設置執行失敗
|
|
|
3756 |
$result["status"]="false";
|
| 226 |
liveuser |
3757 |
|
| 3 |
liveuser |
3758 |
#設置執行錯誤訊息
|
|
|
3759 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
3760 |
|
| 3 |
liveuser |
3761 |
#如果傳入的參數為 null
|
|
|
3762 |
if($conf===null){
|
| 226 |
liveuser |
3763 |
|
| 3 |
liveuser |
3764 |
#設置執行錯誤訊息
|
|
|
3765 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3766 |
|
| 3 |
liveuser |
3767 |
}#if end
|
|
|
3768 |
|
|
|
3769 |
#回傳結果
|
|
|
3770 |
return $result;
|
| 226 |
liveuser |
3771 |
|
| 3 |
liveuser |
3772 |
}#if end
|
| 226 |
liveuser |
3773 |
|
| 3 |
liveuser |
3774 |
#函式說明:
|
|
|
3775 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
3776 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3777 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3778 |
#$result["function"],當前執行的函式名稱.
|
|
|
3779 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3780 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3781 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3782 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3783 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
3784 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
3785 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
3786 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
3787 |
#必填寫的參數:
|
|
|
3788 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
3789 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
3790 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
3791 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","startKeyWord","endKeyWord");
|
|
|
3792 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
3793 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
3794 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
3795 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
3796 |
#可以省略的參數:
|
|
|
3797 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
3798 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
3799 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
3800 |
#$conf["canNotBeEmpty"]=array();
|
|
|
3801 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
3802 |
#$conf["canBeEmpty"]=array();
|
|
|
3803 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
3804 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
3805 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
3806 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
3807 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
3808 |
#$conf["skipableVariableType"]=array();
|
|
|
3809 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
3810 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
3811 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
3812 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
3813 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
3814 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
3815 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
3816 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
3817 |
#參考資料來源:
|
|
|
3818 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
3819 |
#建議:
|
|
|
3820 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
3821 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
3822 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
3823 |
|
| 3 |
liveuser |
3824 |
#如果檢查參數失敗
|
|
|
3825 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
3826 |
|
| 3 |
liveuser |
3827 |
#設置執行失敗
|
|
|
3828 |
$result["status"]="false";
|
| 226 |
liveuser |
3829 |
|
| 3 |
liveuser |
3830 |
#設置執行錯誤訊息
|
|
|
3831 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3832 |
|
| 3 |
liveuser |
3833 |
#回傳結果
|
|
|
3834 |
return $result;
|
| 226 |
liveuser |
3835 |
|
| 3 |
liveuser |
3836 |
}#if end
|
| 226 |
liveuser |
3837 |
|
| 3 |
liveuser |
3838 |
#如果檢查參數不通過
|
|
|
3839 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
3840 |
|
| 3 |
liveuser |
3841 |
#設置執行失敗
|
|
|
3842 |
$result["status"]="false";
|
| 226 |
liveuser |
3843 |
|
| 3 |
liveuser |
3844 |
#設置執行錯誤訊息
|
|
|
3845 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
3846 |
|
| 3 |
liveuser |
3847 |
#回傳結果
|
|
|
3848 |
return $result;
|
| 226 |
liveuser |
3849 |
|
| 3 |
liveuser |
3850 |
}#if end
|
| 226 |
liveuser |
3851 |
|
| 3 |
liveuser |
3852 |
#檢查是否有符合的關鍵字存在
|
|
|
3853 |
#函式說明:
|
|
|
3854 |
#檢查一個字串裡面是否有多個關鍵字
|
|
|
3855 |
#回傳結果:
|
|
|
3856 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗.
|
|
|
3857 |
#$result["error"],錯誤訊息.
|
|
|
3858 |
#$result["function"],當前執行的函數名稱.
|
|
|
3859 |
#$result["founded"],是否有找到的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字.
|
|
|
3860 |
#$result["foundedKeyWords"],找到的關鍵字.
|
|
|
3861 |
#$result["foundedAll"],是否有找到全部的關鍵字,"true"代表有;"false"代表沒有.
|
|
|
3862 |
#$result["argu"],使用的參數.
|
|
|
3863 |
#必填參數:
|
|
|
3864 |
#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
|
|
|
3865 |
$conf["search::findManyKeyWords"]["keyWords"]=array($conf["startKeyWord"],$conf["endKeyWord"]);
|
|
|
3866 |
#$conf["string"],字串,要被搜尋的字串內容.
|
|
|
3867 |
$conf["search::findManyKeyWords"]["string"]=$conf["input"];
|
|
|
3868 |
#可省略參數:
|
|
|
3869 |
#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合.
|
|
|
3870 |
#$conf["completeEqual"]="true";
|
|
|
3871 |
#參考資料:
|
|
|
3872 |
#無.
|
|
|
3873 |
#備註:
|
|
|
3874 |
#無.
|
|
|
3875 |
$findManyKeyWords=search::findManyKeyWords($conf["search::findManyKeyWords"]);
|
|
|
3876 |
unset($conf["search::findManyKeyWords"]);
|
| 226 |
liveuser |
3877 |
|
| 3 |
liveuser |
3878 |
#如果執行失敗
|
|
|
3879 |
if($findManyKeyWords["status"]==="false"){
|
| 226 |
liveuser |
3880 |
|
| 3 |
liveuser |
3881 |
#設置執行失敗
|
|
|
3882 |
$result["status"]="false";
|
| 226 |
liveuser |
3883 |
|
| 3 |
liveuser |
3884 |
#設置執行錯誤訊息
|
|
|
3885 |
$result["error"]=$findManyKeyWords;
|
| 226 |
liveuser |
3886 |
|
| 3 |
liveuser |
3887 |
#回傳結果
|
|
|
3888 |
return $result;
|
| 226 |
liveuser |
3889 |
|
| 3 |
liveuser |
3890 |
}#if end
|
| 226 |
liveuser |
3891 |
|
| 3 |
liveuser |
3892 |
#設置預設有找到關鍵字
|
|
|
3893 |
$result["found"]="true";
|
| 226 |
liveuser |
3894 |
|
| 3 |
liveuser |
3895 |
#如果沒有找到全部關鍵字
|
|
|
3896 |
if($findManyKeyWords["foundedAll"]==="false"){
|
| 226 |
liveuser |
3897 |
|
| 3 |
liveuser |
3898 |
#設置沒有找到關鍵字
|
|
|
3899 |
$result["found"]="false";
|
| 226 |
liveuser |
3900 |
|
| 3 |
liveuser |
3901 |
}#if end
|
| 226 |
liveuser |
3902 |
|
| 3 |
liveuser |
3903 |
#函式說明:
|
|
|
3904 |
#將字串特定關鍵字與其前面的內容剔除
|
|
|
3905 |
#回傳結果:
|
|
|
3906 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3907 |
#$result["error"],錯誤訊息陣列.
|
|
|
3908 |
#$result["warning"],警告訊息鎮列.
|
|
|
3909 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3910 |
#$result["function"],當前執行的函數名稱.
|
|
|
3911 |
#$result["oriStr"],要處理的原始字串內容.
|
| 226 |
liveuser |
3912 |
#$result["content"],處理好的的字串內容.
|
| 3 |
liveuser |
3913 |
#必填參數:
|
|
|
3914 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3915 |
$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$conf["input"];
|
|
|
3916 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3917 |
$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$conf["startKeyWord"];
|
|
|
3918 |
#可省略參數:
|
|
|
3919 |
#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
|
|
|
3920 |
#$conf["recursive"]="true";
|
|
|
3921 |
#參考資料:
|
|
|
3922 |
#無.
|
|
|
3923 |
#備註:
|
|
|
3924 |
#無.
|
|
|
3925 |
$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
|
|
|
3926 |
unset($conf["stringProcess::delStrBeforeKeyWord"]);
|
| 226 |
liveuser |
3927 |
|
| 3 |
liveuser |
3928 |
#如果執行失敗
|
|
|
3929 |
if($delStrBeforeKeyWord["status"]==="false"){
|
| 226 |
liveuser |
3930 |
|
| 3 |
liveuser |
3931 |
#設置執行失敗
|
|
|
3932 |
$result["status"]="false";
|
| 226 |
liveuser |
3933 |
|
| 3 |
liveuser |
3934 |
#設置執行錯誤訊息
|
|
|
3935 |
$result["error"]=$delStrBeforeKeyWord;
|
| 226 |
liveuser |
3936 |
|
| 3 |
liveuser |
3937 |
#回傳結果
|
|
|
3938 |
return $result;
|
| 226 |
liveuser |
3939 |
|
| 3 |
liveuser |
3940 |
}#if end
|
| 226 |
liveuser |
3941 |
|
| 3 |
liveuser |
3942 |
#函式說明:
|
|
|
3943 |
#將字串特定關鍵字與其後面的內容剔除
|
|
|
3944 |
#回傳結果:
|
|
|
3945 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3946 |
#$result["error"],錯誤訊息陣列.
|
|
|
3947 |
#$result["warning"],警告訊息鎮列.
|
|
|
3948 |
#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
|
|
|
3949 |
#$result["function"],當前執行的函數名稱.
|
|
|
3950 |
#$result["oriStr"],要處理的原始字串內容.
|
|
|
3951 |
#$result["content"],處理好的的字串內容.
|
|
|
3952 |
#$result["argu"],使用的參數.
|
|
|
3953 |
#必填參數:
|
|
|
3954 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
3955 |
$conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$delStrBeforeKeyWord["content"];
|
|
|
3956 |
#$conf["keyWord"],字串,特定字串.
|
|
|
3957 |
$conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=$conf["endKeyWord"];
|
|
|
3958 |
#可省略參數:
|
|
|
3959 |
#無.
|
|
|
3960 |
#參考資料:
|
|
|
3961 |
#無.
|
|
|
3962 |
#備註:
|
|
|
3963 |
#無.
|
|
|
3964 |
$delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
|
|
|
3965 |
unset($conf["stringProcess::delStrAfterKeyWord"]);
|
| 226 |
liveuser |
3966 |
|
| 3 |
liveuser |
3967 |
#如果執行失敗
|
|
|
3968 |
if($delStrAfterKeyWord["status"]==="false"){
|
| 226 |
liveuser |
3969 |
|
| 3 |
liveuser |
3970 |
#設置執行失敗
|
|
|
3971 |
$result["status"]="false";
|
| 226 |
liveuser |
3972 |
|
| 3 |
liveuser |
3973 |
#設置執行錯誤訊息
|
|
|
3974 |
$result["error"]=$delStrAfterKeyWord;
|
| 226 |
liveuser |
3975 |
|
| 3 |
liveuser |
3976 |
#回傳結果
|
|
|
3977 |
return $result;
|
| 226 |
liveuser |
3978 |
|
| 3 |
liveuser |
3979 |
}#if end
|
| 226 |
liveuser |
3980 |
|
| 3 |
liveuser |
3981 |
#設置原始內容
|
|
|
3982 |
$result["oriStr"]=$conf["input"];
|
| 226 |
liveuser |
3983 |
|
| 3 |
liveuser |
3984 |
#設置處理後的內容
|
|
|
3985 |
$result["content"]=$delStrAfterKeyWord["content"];
|
| 226 |
liveuser |
3986 |
|
| 3 |
liveuser |
3987 |
#設置執行正常
|
|
|
3988 |
$result["status"]="true";
|
| 226 |
liveuser |
3989 |
|
| 3 |
liveuser |
3990 |
#回傳結果
|
|
|
3991 |
return $result;
|
| 226 |
liveuser |
3992 |
|
| 3 |
liveuser |
3993 |
}#function getContentBetweenKeyWord end
|
|
|
3994 |
|
|
|
3995 |
/*
|
|
|
3996 |
#函式說明:
|
|
|
3997 |
#將字串進行解析,變成多個參數.
|
|
|
3998 |
#回傳結果:
|
|
|
3999 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4000 |
#$result["function"],當前執行的函式內容.
|
|
|
4001 |
#$result["error"],錯誤訊息陣列.
|
|
|
4002 |
#$result["content"],參數陣列.
|
|
|
4003 |
#$result["count"],總共有幾個參數.
|
|
|
4004 |
#必填參數:
|
|
|
4005 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
4006 |
$conf["input"]="";
|
|
|
4007 |
#可省略參數:
|
|
|
4008 |
#無.
|
|
|
4009 |
#參考資料:
|
|
|
4010 |
#無.
|
|
|
4011 |
#備註:
|
|
|
4012 |
#無.
|
|
|
4013 |
*/
|
|
|
4014 |
public static function parse(&$conf){
|
| 226 |
liveuser |
4015 |
|
| 3 |
liveuser |
4016 |
#初始化要回傳的結果
|
|
|
4017 |
$result=array();
|
|
|
4018 |
|
|
|
4019 |
#取得當前執行的函數名稱
|
|
|
4020 |
$result["function"]=__FUNCTION__;
|
|
|
4021 |
|
|
|
4022 |
#如果沒有參數
|
|
|
4023 |
if(func_num_args()==0){
|
| 226 |
liveuser |
4024 |
|
| 3 |
liveuser |
4025 |
#設置執行失敗
|
|
|
4026 |
$result["status"]="false";
|
| 226 |
liveuser |
4027 |
|
| 3 |
liveuser |
4028 |
#設置執行錯誤訊息
|
|
|
4029 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
4030 |
|
| 3 |
liveuser |
4031 |
#回傳結果
|
|
|
4032 |
return $result;
|
| 226 |
liveuser |
4033 |
|
| 3 |
liveuser |
4034 |
}#if end
|
|
|
4035 |
|
|
|
4036 |
#取得參數
|
|
|
4037 |
$result["argu"]=$conf;
|
|
|
4038 |
|
|
|
4039 |
#如果 $conf 不為陣列
|
|
|
4040 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
4041 |
|
| 3 |
liveuser |
4042 |
#設置執行失敗
|
|
|
4043 |
$result["status"]="false";
|
| 226 |
liveuser |
4044 |
|
| 3 |
liveuser |
4045 |
#設置執行錯誤訊息
|
|
|
4046 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
4047 |
|
| 3 |
liveuser |
4048 |
#如果傳入的參數為 null
|
|
|
4049 |
if($conf===null){
|
| 226 |
liveuser |
4050 |
|
| 3 |
liveuser |
4051 |
#設置執行錯誤訊息
|
|
|
4052 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4053 |
|
| 3 |
liveuser |
4054 |
}#if end
|
|
|
4055 |
|
|
|
4056 |
#回傳結果
|
|
|
4057 |
return $result;
|
| 226 |
liveuser |
4058 |
|
| 3 |
liveuser |
4059 |
}#if end
|
| 226 |
liveuser |
4060 |
|
| 3 |
liveuser |
4061 |
#函式說明:
|
|
|
4062 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4063 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4064 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4065 |
#$result["function"],當前執行的函式名稱.
|
|
|
4066 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4067 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4068 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4069 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4070 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4071 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4072 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4073 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4074 |
#必填寫的參數:
|
|
|
4075 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4076 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4077 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4078 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
4079 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4080 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4081 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4082 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4083 |
#可以省略的參數:
|
|
|
4084 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4085 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
4086 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4087 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4088 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4089 |
#$conf["canBeEmpty"]=array();
|
|
|
4090 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4091 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4092 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4093 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
4094 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4095 |
#$conf["skipableVariableType"]=array();
|
|
|
4096 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4097 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4098 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4099 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4100 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4101 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4102 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4103 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4104 |
#參考資料來源:
|
|
|
4105 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4106 |
#建議:
|
|
|
4107 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4108 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4109 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4110 |
|
| 3 |
liveuser |
4111 |
#如果檢查參數失敗
|
|
|
4112 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
4113 |
|
| 3 |
liveuser |
4114 |
#設置執行失敗
|
|
|
4115 |
$result["status"]="false";
|
| 226 |
liveuser |
4116 |
|
| 3 |
liveuser |
4117 |
#設置執行錯誤訊息
|
|
|
4118 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4119 |
|
| 3 |
liveuser |
4120 |
#回傳結果
|
|
|
4121 |
return $result;
|
| 226 |
liveuser |
4122 |
|
| 3 |
liveuser |
4123 |
}#if end
|
| 226 |
liveuser |
4124 |
|
| 3 |
liveuser |
4125 |
#如果檢查參數不通過
|
|
|
4126 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4127 |
|
| 3 |
liveuser |
4128 |
#設置執行失敗
|
|
|
4129 |
$result["status"]="false";
|
| 226 |
liveuser |
4130 |
|
| 3 |
liveuser |
4131 |
#設置執行錯誤訊息
|
|
|
4132 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4133 |
|
| 3 |
liveuser |
4134 |
#回傳結果
|
|
|
4135 |
return $result;
|
| 226 |
liveuser |
4136 |
|
| 3 |
liveuser |
4137 |
}#if end
|
| 226 |
liveuser |
4138 |
|
| 3 |
liveuser |
4139 |
#預設存放 qbpwcf 可執行程式 parse 的位置
|
|
|
4140 |
$defaultQbpwcfUsrBinParse="/usr/bin/parse";
|
|
|
4141 |
|
|
|
4142 |
#預設存放 qbpwcf local 可執行程式 parse 的位置
|
| 21 |
liveuser |
4143 |
$defaultLocalQbpwcfUsrBinParse=pathinfo(__FILE__)["dirname"]."/../../bin/parse";
|
| 3 |
liveuser |
4144 |
|
|
|
4145 |
#預設存放 qbpwcf 可執行程式 parse 的位置
|
|
|
4146 |
$qbpwcfUsrBinParseArray=array($defaultLocalQbpwcfUsrBinParse,$defaultQbpwcfUsrBinParse);
|
|
|
4147 |
|
|
|
4148 |
#如果存在 include path
|
|
|
4149 |
if(get_include_path()!==false){
|
| 226 |
liveuser |
4150 |
|
| 3 |
liveuser |
4151 |
#函式說明:
|
|
|
4152 |
#將固定格式的字串分開,並回傳分開的結果.
|
|
|
4153 |
#回傳結果:
|
|
|
4154 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4155 |
#$result["error"],錯誤訊息陣列
|
|
|
4156 |
#$result["function"],當前執行的函數名稱.
|
|
|
4157 |
#$result["argu"],使用的參數.
|
|
|
4158 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4159 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4160 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4161 |
#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
|
|
|
4162 |
#必填參數:
|
|
|
4163 |
#$conf["stringIn"],字串,要處理的字串.
|
|
|
4164 |
$conf["stringProcess::spiltString"]["stringIn"]=get_include_path();
|
|
|
4165 |
#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
|
|
|
4166 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=":";
|
|
|
4167 |
#可省略參數:
|
|
|
4168 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
4169 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
4170 |
#參考資料:
|
|
|
4171 |
#無.
|
|
|
4172 |
#備註:
|
|
|
4173 |
#無.
|
|
|
4174 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
4175 |
unset($conf["stringProcess::spiltString"]);
|
|
|
4176 |
|
|
|
4177 |
#如果執行失敗
|
|
|
4178 |
if($spiltString["status"]==="false"){
|
| 226 |
liveuser |
4179 |
|
| 3 |
liveuser |
4180 |
#設置執行失敗
|
|
|
4181 |
$result["status"]="false";
|
|
|
4182 |
|
|
|
4183 |
#設置執行錯誤
|
|
|
4184 |
$result["error"]=$spiltString;
|
|
|
4185 |
|
|
|
4186 |
#回傳結果
|
|
|
4187 |
return $result;
|
| 226 |
liveuser |
4188 |
|
| 3 |
liveuser |
4189 |
}#if end
|
| 226 |
liveuser |
4190 |
|
| 3 |
liveuser |
4191 |
#如果沒有符合的分割符號
|
|
|
4192 |
if($spiltString["found"]==="false"){
|
| 226 |
liveuser |
4193 |
|
| 3 |
liveuser |
4194 |
#設置執行失敗
|
|
|
4195 |
$result["status"]="false";
|
|
|
4196 |
|
|
|
4197 |
#設置執行錯誤
|
|
|
4198 |
$result["error"]=$spiltString;
|
|
|
4199 |
|
|
|
4200 |
#回傳結果
|
|
|
4201 |
return $result;
|
| 226 |
liveuser |
4202 |
|
| 3 |
liveuser |
4203 |
}#if end
|
| 226 |
liveuser |
4204 |
|
| 3 |
liveuser |
4205 |
#如果沒有切割出東西
|
|
|
4206 |
if($spiltString["dataCounts"]<1){
|
| 226 |
liveuser |
4207 |
|
| 3 |
liveuser |
4208 |
#設置執行失敗
|
|
|
4209 |
$result["status"]="false";
|
|
|
4210 |
|
|
|
4211 |
#設置執行錯誤
|
|
|
4212 |
$result["error"]=$spiltString;
|
|
|
4213 |
|
|
|
4214 |
#回傳結果
|
|
|
4215 |
return $result;
|
| 226 |
liveuser |
4216 |
|
| 3 |
liveuser |
4217 |
}#if end
|
| 226 |
liveuser |
4218 |
|
| 3 |
liveuser |
4219 |
#增加存放 qbpwcf 可執行程式 parse 的位置
|
|
|
4220 |
$qbpwcfUsrBinParseArray[]=$spiltString["dataArray"][0].$defaultQbpwcfUsrBinParse;
|
|
|
4221 |
|
|
|
4222 |
}#if end
|
| 226 |
liveuser |
4223 |
|
| 3 |
liveuser |
4224 |
#針對每個可能的 存放 qbpwcf 可執行程式的位置
|
|
|
4225 |
foreach($qbpwcfUsrBinParseArray as $index=>$qbpwcfUsrBinParse){
|
| 226 |
liveuser |
4226 |
|
| 3 |
liveuser |
4227 |
#如果檔案不存在
|
|
|
4228 |
if(!file_exists($qbpwcfUsrBinParse)){
|
|
|
4229 |
|
|
|
4230 |
#如果是最後一個檔案了
|
|
|
4231 |
if($index===count($qbpwcfUsrBinParseArray)-1){
|
| 226 |
liveuser |
4232 |
|
| 3 |
liveuser |
4233 |
#設置執行失敗
|
|
|
4234 |
$result["status"]="false";
|
|
|
4235 |
|
|
|
4236 |
#設置執行錯誤
|
|
|
4237 |
$result["error"]="檔案(".$qbpwcfUsrBinParse.")不存在";
|
|
|
4238 |
|
|
|
4239 |
#回傳結果
|
|
|
4240 |
return $result;
|
| 226 |
liveuser |
4241 |
|
| 3 |
liveuser |
4242 |
}#if end
|
| 226 |
liveuser |
4243 |
|
| 3 |
liveuser |
4244 |
}#if end
|
| 226 |
liveuser |
4245 |
|
| 3 |
liveuser |
4246 |
#反之檔案存在
|
|
|
4247 |
else{
|
| 226 |
liveuser |
4248 |
|
| 3 |
liveuser |
4249 |
#更新預設的 usr/bin/parse 位置
|
|
|
4250 |
$defaultQbpwcfUsrBinParse=$qbpwcfUsrBinParse;
|
| 226 |
liveuser |
4251 |
|
| 3 |
liveuser |
4252 |
#跳出 foreach
|
|
|
4253 |
break;
|
| 226 |
liveuser |
4254 |
|
| 3 |
liveuser |
4255 |
}#else end
|
| 226 |
liveuser |
4256 |
|
| 3 |
liveuser |
4257 |
}#foreach end
|
| 226 |
liveuser |
4258 |
|
| 3 |
liveuser |
4259 |
#建立暫存script檔案
|
|
|
4260 |
#函式說明:
|
| 226 |
liveuser |
4261 |
#於本套件位置底下的tmp資料夾下建立與回傳暫存檔案名稱路徑
|
| 3 |
liveuser |
4262 |
#回傳結果:
|
|
|
4263 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4264 |
#$result["error"],錯誤訊息.
|
|
|
4265 |
#$result["function"],當前執行的函數名稱.
|
|
|
4266 |
#$result["content"],暫存檔案的路徑與名稱.
|
|
|
4267 |
#$result["fileName"],暫存檔案的名稱.
|
|
|
4268 |
#$result["path"],暫存檔案的路徑.
|
|
|
4269 |
#必填參數:
|
|
|
4270 |
#無.
|
|
|
4271 |
#可省略參數:
|
|
|
4272 |
#無.
|
|
|
4273 |
#參考資料:
|
|
|
4274 |
#無.
|
|
|
4275 |
#備註:
|
|
|
4276 |
#無.
|
| 33 |
liveuser |
4277 |
$conf["fileAccess::createTempFile"]=array();
|
|
|
4278 |
$createTempFile=fileAccess::createTempFile($conf["fileAccess::createTempFile"]);
|
|
|
4279 |
unset($conf["fileAccess::createTempFile"]);
|
| 226 |
liveuser |
4280 |
|
| 3 |
liveuser |
4281 |
#如果沒有符合的分割符號
|
|
|
4282 |
if($createTempFile["status"]==="false"){
|
| 226 |
liveuser |
4283 |
|
| 3 |
liveuser |
4284 |
#設置執行失敗
|
|
|
4285 |
$result["status"]="false";
|
|
|
4286 |
|
|
|
4287 |
#設置執行錯誤
|
|
|
4288 |
$result["error"]=$createTempFile;
|
|
|
4289 |
|
|
|
4290 |
#回傳結果
|
|
|
4291 |
return $result;
|
| 226 |
liveuser |
4292 |
|
| 3 |
liveuser |
4293 |
}#if end
|
| 226 |
liveuser |
4294 |
|
| 3 |
liveuser |
4295 |
#取得暫存檔案的路徑與名稱
|
|
|
4296 |
$scriptFile2test=$createTempFile["content"];
|
| 226 |
liveuser |
4297 |
|
| 3 |
liveuser |
4298 |
#將要檢查的shell script寫入
|
|
|
4299 |
#函式說明:
|
|
|
4300 |
#將字串寫入到檔案
|
|
|
4301 |
#回傳結果:
|
|
|
4302 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
4303 |
#$result["error"],錯誤訊息陣列.
|
|
|
4304 |
#$result["function"],當前執行的函數名稱.
|
|
|
4305 |
#$result["fileInfo"],實際上寫入的檔案資訊陣列.
|
|
|
4306 |
#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
|
|
|
4307 |
#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
|
|
|
4308 |
#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
4309 |
#$result["argu"],使用的參數.
|
|
|
4310 |
#必填參數:
|
|
|
4311 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4312 |
$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
|
|
|
4313 |
#可省略參數:
|
|
|
4314 |
#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
|
|
|
4315 |
$conf["fileAccess::writeTextIntoFile"]["fileName"]=$scriptFile2test;
|
|
|
4316 |
#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
|
|
|
4317 |
$conf["fileAccess::writeTextIntoFile"]["inputString"]="#!/bin/bash".PHP_EOL.$conf["input"].PHP_EOL;
|
|
|
4318 |
#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
|
|
|
4319 |
#$conf["writeMethod"]="a";
|
|
|
4320 |
#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
|
|
|
4321 |
#$conf["checkRepeat"]="";
|
|
|
4322 |
#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
4323 |
#$conf["filenameExtensionStartPoint"]="";
|
|
|
4324 |
#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
|
|
|
4325 |
#$conf["repeatNameRule"]="";
|
|
|
4326 |
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
|
|
|
4327 |
$conf["fileAccess::writeTextIntoFile"]["web"]="false";
|
|
|
4328 |
#參考資料:
|
|
|
4329 |
#無.
|
|
|
4330 |
#備註:
|
|
|
4331 |
#無.
|
|
|
4332 |
$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
|
|
|
4333 |
unset($conf["fileAccess::writeTextIntoFile"]);
|
| 226 |
liveuser |
4334 |
|
| 3 |
liveuser |
4335 |
#如果執行失敗
|
|
|
4336 |
if($writeTextIntoFile["status"]==="false"){
|
| 226 |
liveuser |
4337 |
|
| 3 |
liveuser |
4338 |
#設置執行失敗
|
|
|
4339 |
$result["status"]="false";
|
|
|
4340 |
|
|
|
4341 |
#設置執行錯誤
|
|
|
4342 |
$result["error"]=$writeTextIntoFile;
|
|
|
4343 |
|
|
|
4344 |
#回傳結果
|
|
|
4345 |
return $result;
|
| 226 |
liveuser |
4346 |
|
| 3 |
liveuser |
4347 |
}#if end
|
| 226 |
liveuser |
4348 |
|
| 3 |
liveuser |
4349 |
#檢查有無語法錯誤
|
|
|
4350 |
$cmd="bash -n ".$scriptFile2test;
|
| 226 |
liveuser |
4351 |
|
| 3 |
liveuser |
4352 |
#函式說明:
|
|
|
4353 |
#透過proc來多執行序運作.
|
|
|
4354 |
#回傳結果:
|
|
|
4355 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4356 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4357 |
#$result["function"],當前執行的函式名稱.
|
|
|
4358 |
#$result["argu"],使用的參數.
|
|
|
4359 |
#$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"代表程序的資訊.
|
|
|
4360 |
#必填參數:
|
|
|
4361 |
#$conf["cmds"],字串陣列,每個元素代表要執行的指令與參數.
|
|
|
4362 |
$conf["threads::proc"]["cmds"]=array($cmd);
|
|
|
4363 |
#可省略參數:
|
|
|
4364 |
#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
|
|
|
4365 |
#$conf["threads::proc"]["wait"]="false";
|
|
|
4366 |
#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
|
|
|
4367 |
#$conf["workingDir"]=array("path");
|
|
|
4368 |
#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
|
|
|
4369 |
#$conf["envs"]=array(array("key"=>"value"));
|
|
|
4370 |
#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
|
|
|
4371 |
#$conf["executeBy"]=array("bash");
|
|
|
4372 |
#參考資料:
|
|
|
4373 |
#https://www.php.net/manual/en/function.proc-open.php
|
|
|
4374 |
#https://www.php.net/manual/en/function.proc-get-status.php
|
|
|
4375 |
#備註:
|
|
|
4376 |
#若需要取得當下的執行狀況,請使用 self::proc_update 來更新.
|
|
|
4377 |
$proc=threads::proc($conf["threads::proc"]);
|
|
|
4378 |
unset($conf["threads::proc"]);
|
| 226 |
liveuser |
4379 |
|
| 3 |
liveuser |
4380 |
#如果執行失敗
|
|
|
4381 |
if($proc["status"]==="false"){
|
| 226 |
liveuser |
4382 |
|
| 3 |
liveuser |
4383 |
#設置執行失敗
|
|
|
4384 |
$result["status"]="false";
|
|
|
4385 |
|
|
|
4386 |
#設置錯誤訊息
|
|
|
4387 |
$result["error"][]="檢查bash語法出錯";
|
|
|
4388 |
|
|
|
4389 |
#設置執行錯誤
|
|
|
4390 |
$result["error"][]=$proc;
|
|
|
4391 |
|
|
|
4392 |
#回傳結果
|
|
|
4393 |
return $result;
|
| 226 |
liveuser |
4394 |
|
| 3 |
liveuser |
4395 |
}#if end
|
| 226 |
liveuser |
4396 |
|
| 3 |
liveuser |
4397 |
#如果執行失敗
|
|
|
4398 |
if($proc["content"][0]["statusCode"]!==0){
|
| 226 |
liveuser |
4399 |
|
| 3 |
liveuser |
4400 |
#如果錯誤訊息為語法錯誤
|
|
|
4401 |
if(strpos($proc["content"][0]["error"],"syntax error")!==false){
|
| 226 |
liveuser |
4402 |
|
| 3 |
liveuser |
4403 |
#遞迴呼叫
|
|
|
4404 |
#函式說明:
|
|
|
4405 |
#將字串進行解析,變成多個參數.
|
|
|
4406 |
#回傳結果:
|
|
|
4407 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4408 |
#$result["function"],當前執行的函式內容.
|
|
|
4409 |
#$result["error"],錯誤訊息陣列.
|
|
|
4410 |
#$result["content"],參數陣列.
|
|
|
4411 |
#$result["count"],總共有幾個參數.
|
|
|
4412 |
#必填參數:
|
|
|
4413 |
#$conf["input"],字串,要解析成參數的字串.
|
|
|
4414 |
$conf["self::parse"]["input"]=\escapeshellarg($conf["input"]);
|
|
|
4415 |
#可省略參數:
|
|
|
4416 |
#無.
|
|
|
4417 |
#參考資料:
|
|
|
4418 |
#無.
|
|
|
4419 |
#備註:
|
|
|
4420 |
#無.
|
|
|
4421 |
$parse=self::parse($conf["self::parse"]);
|
|
|
4422 |
unset($conf["self::parse"]);
|
| 226 |
liveuser |
4423 |
|
| 3 |
liveuser |
4424 |
#回傳結果
|
|
|
4425 |
return $parse;
|
| 226 |
liveuser |
4426 |
|
| 3 |
liveuser |
4427 |
}#if end
|
| 226 |
liveuser |
4428 |
|
| 3 |
liveuser |
4429 |
#取得錯誤訊息
|
| 226 |
liveuser |
4430 |
|
| 3 |
liveuser |
4431 |
#設置執行失敗
|
|
|
4432 |
$result["status"]="false";
|
|
|
4433 |
|
|
|
4434 |
#設置錯誤訊息
|
|
|
4435 |
$result["error"][]="Bash syntax error or Permission denied";
|
|
|
4436 |
|
|
|
4437 |
#設置執行錯誤
|
|
|
4438 |
$result["error"][]=$proc;
|
|
|
4439 |
|
|
|
4440 |
#回傳結果
|
|
|
4441 |
return $result;
|
| 226 |
liveuser |
4442 |
|
| 3 |
liveuser |
4443 |
}#if end
|
| 226 |
liveuser |
4444 |
|
| 3 |
liveuser |
4445 |
#移除暫存檔案
|
|
|
4446 |
unlink($scriptFile2test);
|
| 226 |
liveuser |
4447 |
|
| 3 |
liveuser |
4448 |
#預設要運行的指令
|
|
|
4449 |
$cmd=$defaultQbpwcfUsrBinParse.' '.$conf["input"];
|
| 226 |
liveuser |
4450 |
|
| 3 |
liveuser |
4451 |
#執行印出參數的php程式
|
|
|
4452 |
exec($cmd,$output,$status);
|
| 226 |
liveuser |
4453 |
|
| 3 |
liveuser |
4454 |
#如果運行正常
|
|
|
4455 |
if($status===0){
|
| 226 |
liveuser |
4456 |
|
| 3 |
liveuser |
4457 |
#設置執行正常
|
|
|
4458 |
$result["status"]="true";
|
| 226 |
liveuser |
4459 |
|
| 3 |
liveuser |
4460 |
#如果輸出不是 json
|
|
|
4461 |
if(json_validate($output[0])===false){
|
| 226 |
liveuser |
4462 |
|
| 3 |
liveuser |
4463 |
#設置執行失敗
|
|
|
4464 |
$result["status"]="false";
|
| 226 |
liveuser |
4465 |
|
| 3 |
liveuser |
4466 |
#設置執行錯誤訊息
|
|
|
4467 |
$result["error"][]="not json output";
|
| 226 |
liveuser |
4468 |
|
| 3 |
liveuser |
4469 |
#設置執行錯誤訊息
|
|
|
4470 |
$result["error"][]=$output;
|
| 226 |
liveuser |
4471 |
|
| 3 |
liveuser |
4472 |
#回傳結果
|
|
|
4473 |
return $result;
|
| 226 |
liveuser |
4474 |
|
| 3 |
liveuser |
4475 |
}#if end
|
| 226 |
liveuser |
4476 |
|
| 3 |
liveuser |
4477 |
#解析json,並轉成array
|
|
|
4478 |
$output=(array)json_decode($output[0]);
|
| 226 |
liveuser |
4479 |
|
| 3 |
liveuser |
4480 |
#移除被執行的php檔案名稱
|
|
|
4481 |
unset($output[0]);
|
| 226 |
liveuser |
4482 |
|
| 3 |
liveuser |
4483 |
#初始化參數陣列
|
|
|
4484 |
$params=array();
|
| 226 |
liveuser |
4485 |
|
| 3 |
liveuser |
4486 |
#針對每個參數
|
|
|
4487 |
foreach($output as $param){
|
| 226 |
liveuser |
4488 |
|
| 3 |
liveuser |
4489 |
#取得參數
|
|
|
4490 |
$params[]=$param;
|
| 226 |
liveuser |
4491 |
|
| 3 |
liveuser |
4492 |
}#foreach end
|
| 226 |
liveuser |
4493 |
|
| 3 |
liveuser |
4494 |
#取得參數陣列
|
|
|
4495 |
$result["content"]=$params;
|
| 226 |
liveuser |
4496 |
|
| 3 |
liveuser |
4497 |
#取得參數數目
|
|
|
4498 |
$result["count"]=count($params);
|
| 226 |
liveuser |
4499 |
|
| 3 |
liveuser |
4500 |
#回傳結果
|
|
|
4501 |
return $result;
|
| 226 |
liveuser |
4502 |
|
| 3 |
liveuser |
4503 |
}#if end
|
| 226 |
liveuser |
4504 |
|
| 3 |
liveuser |
4505 |
#反之運行不正常
|
|
|
4506 |
else{
|
|
|
4507 |
#設置執行正常
|
|
|
4508 |
$result["status"]="false";
|
| 226 |
liveuser |
4509 |
|
| 3 |
liveuser |
4510 |
#設置錯誤訊息
|
|
|
4511 |
$result["error"][]="解析字串出錯";
|
| 226 |
liveuser |
4512 |
|
| 3 |
liveuser |
4513 |
#設置 escaped 過後的 input 資訊到錯誤訊息陣列裡面
|
|
|
4514 |
$result["error"][]="escaped input:".escapeshellarg($conf["input"]);
|
| 226 |
liveuser |
4515 |
|
| 3 |
liveuser |
4516 |
#回傳結果
|
|
|
4517 |
return $result;
|
| 226 |
liveuser |
4518 |
|
| 3 |
liveuser |
4519 |
}#else end
|
| 226 |
liveuser |
4520 |
|
| 3 |
liveuser |
4521 |
}#function parse end
|
| 226 |
liveuser |
4522 |
|
| 3 |
liveuser |
4523 |
/*
|
|
|
4524 |
#函式說明:
|
|
|
4525 |
#清除字串的「"」或「'」符號.
|
|
|
4526 |
#回傳結果:
|
|
|
4527 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4528 |
#$result["function"],當前執行的函式內容.
|
|
|
4529 |
#$result["error"],錯誤訊息陣列.
|
|
|
4530 |
#$result["content"],剔除「"」或「'」符號後的字串.
|
|
|
4531 |
#必填參數:
|
|
|
4532 |
#$conf["str"],字串,要處理的字串.
|
|
|
4533 |
$conf["str"]="";
|
|
|
4534 |
#可省略參數:
|
|
|
4535 |
#無.
|
|
|
4536 |
#參考資料:
|
|
|
4537 |
#無.
|
|
|
4538 |
#備註:
|
|
|
4539 |
#無.
|
|
|
4540 |
*/
|
|
|
4541 |
public static function clearStrSymbol(&$conf){
|
| 226 |
liveuser |
4542 |
|
| 3 |
liveuser |
4543 |
#初始化要回傳的結果
|
|
|
4544 |
$result=array();
|
|
|
4545 |
|
|
|
4546 |
#取得當前執行的函數名稱
|
|
|
4547 |
$result["function"]=__FUNCTION__;
|
|
|
4548 |
|
|
|
4549 |
#如果沒有參數
|
|
|
4550 |
if(func_num_args()==0){
|
| 226 |
liveuser |
4551 |
|
| 3 |
liveuser |
4552 |
#設置執行失敗
|
|
|
4553 |
$result["status"]="false";
|
| 226 |
liveuser |
4554 |
|
| 3 |
liveuser |
4555 |
#設置執行錯誤訊息
|
|
|
4556 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
4557 |
|
| 3 |
liveuser |
4558 |
#回傳結果
|
|
|
4559 |
return $result;
|
| 226 |
liveuser |
4560 |
|
| 3 |
liveuser |
4561 |
}#if end
|
|
|
4562 |
|
|
|
4563 |
#取得參數
|
|
|
4564 |
$result["argu"]=$conf;
|
|
|
4565 |
|
|
|
4566 |
#如果 $conf 不為陣列
|
|
|
4567 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
4568 |
|
| 3 |
liveuser |
4569 |
#設置執行失敗
|
|
|
4570 |
$result["status"]="false";
|
| 226 |
liveuser |
4571 |
|
| 3 |
liveuser |
4572 |
#設置執行錯誤訊息
|
|
|
4573 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
4574 |
|
| 3 |
liveuser |
4575 |
#如果傳入的參數為 null
|
|
|
4576 |
if($conf===null){
|
| 226 |
liveuser |
4577 |
|
| 3 |
liveuser |
4578 |
#設置執行錯誤訊息
|
|
|
4579 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4580 |
|
| 3 |
liveuser |
4581 |
}#if end
|
|
|
4582 |
|
|
|
4583 |
#回傳結果
|
|
|
4584 |
return $result;
|
| 226 |
liveuser |
4585 |
|
| 3 |
liveuser |
4586 |
}#if end
|
| 226 |
liveuser |
4587 |
|
| 3 |
liveuser |
4588 |
#函式說明:
|
|
|
4589 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4590 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4591 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4592 |
#$result["function"],當前執行的函式名稱.
|
|
|
4593 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4594 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4595 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4596 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4597 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4598 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4599 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4600 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4601 |
#必填寫的參數:
|
|
|
4602 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4603 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4604 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4605 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("str");
|
|
|
4606 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4607 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4608 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4609 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4610 |
#可以省略的參數:
|
|
|
4611 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4612 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
4613 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4614 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4615 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4616 |
#$conf["canBeEmpty"]=array();
|
|
|
4617 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4618 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4619 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4620 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
4621 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4622 |
#$conf["skipableVariableType"]=array();
|
|
|
4623 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4624 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4625 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4626 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4627 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4628 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4629 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4630 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4631 |
#參考資料來源:
|
|
|
4632 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4633 |
#建議:
|
|
|
4634 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4635 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4636 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4637 |
|
| 3 |
liveuser |
4638 |
#如果檢查參數失敗
|
|
|
4639 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
4640 |
|
| 3 |
liveuser |
4641 |
#設置執行失敗
|
|
|
4642 |
$result["status"]="false";
|
| 226 |
liveuser |
4643 |
|
| 3 |
liveuser |
4644 |
#設置執行錯誤訊息
|
|
|
4645 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4646 |
|
| 3 |
liveuser |
4647 |
#回傳結果
|
|
|
4648 |
return $result;
|
| 226 |
liveuser |
4649 |
|
| 3 |
liveuser |
4650 |
}#if end
|
| 226 |
liveuser |
4651 |
|
| 3 |
liveuser |
4652 |
#如果檢查參數不通過
|
|
|
4653 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4654 |
|
| 3 |
liveuser |
4655 |
#設置執行失敗
|
|
|
4656 |
$result["status"]="false";
|
| 226 |
liveuser |
4657 |
|
| 3 |
liveuser |
4658 |
#設置執行錯誤訊息
|
|
|
4659 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4660 |
|
| 3 |
liveuser |
4661 |
#回傳結果
|
|
|
4662 |
return $result;
|
| 226 |
liveuser |
4663 |
|
| 3 |
liveuser |
4664 |
}#if end
|
| 226 |
liveuser |
4665 |
|
| 3 |
liveuser |
4666 |
#取得參數
|
|
|
4667 |
$str=$conf["str"];
|
| 226 |
liveuser |
4668 |
|
| 3 |
liveuser |
4669 |
#檢查是否有「"」在開頭
|
| 226 |
liveuser |
4670 |
$strHeadSymbol1=strpos($str,"\"");
|
|
|
4671 |
|
| 3 |
liveuser |
4672 |
#檢查是否有「'」在開頭
|
|
|
4673 |
$strHeadSymbol2=strpos($str,"'");
|
| 226 |
liveuser |
4674 |
|
| 3 |
liveuser |
4675 |
#分割輸入的字串為一個個字的陣列
|
| 226 |
liveuser |
4676 |
$splitedFileName=str_split($str);
|
|
|
4677 |
|
| 3 |
liveuser |
4678 |
#取得輸入參數的長度
|
|
|
4679 |
$fileNameStrlen=strlen($str);
|
|
|
4680 |
|
|
|
4681 |
#如果檔案名稱被「"」或「'」包住
|
|
|
4682 |
if
|
|
|
4683 |
(
|
| 226 |
liveuser |
4684 |
$strHeadSymbol1===0 && $splitedFileName[$fileNameStrlen-1]==="\""
|
| 3 |
liveuser |
4685 |
||
|
| 226 |
liveuser |
4686 |
$strHeadSymbol2===0 && $splitedFileName[$fileNameStrlen-1]==="'"
|
| 3 |
liveuser |
4687 |
){
|
| 226 |
liveuser |
4688 |
|
| 3 |
liveuser |
4689 |
#初始化儲存處理好的字串
|
|
|
4690 |
$fixedStr="";
|
| 226 |
liveuser |
4691 |
|
| 3 |
liveuser |
4692 |
#將字串的「"」包住的內容
|
|
|
4693 |
for($i=1;$i<$fileNameStrlen-1;$i++){
|
| 226 |
liveuser |
4694 |
|
| 3 |
liveuser |
4695 |
#取出
|
|
|
4696 |
$fixedStr=$fixedStr.$splitedFileName[$i];
|
| 226 |
liveuser |
4697 |
|
| 3 |
liveuser |
4698 |
}#for end
|
| 226 |
liveuser |
4699 |
|
| 3 |
liveuser |
4700 |
#儲存處理好的字串
|
|
|
4701 |
$result["content"]=$fixedStr;
|
| 226 |
liveuser |
4702 |
|
| 3 |
liveuser |
4703 |
}#if end
|
| 226 |
liveuser |
4704 |
|
| 3 |
liveuser |
4705 |
#儲存原先的字串
|
|
|
4706 |
$result["content"]=$str;
|
| 226 |
liveuser |
4707 |
|
| 3 |
liveuser |
4708 |
#設置執行正常
|
|
|
4709 |
$result["status"]="true";
|
| 226 |
liveuser |
4710 |
|
| 3 |
liveuser |
4711 |
#回傳結果
|
|
|
4712 |
return $result;
|
| 226 |
liveuser |
4713 |
|
| 3 |
liveuser |
4714 |
}#function clearStrSymbol end
|
| 226 |
liveuser |
4715 |
|
| 3 |
liveuser |
4716 |
/*
|
|
|
4717 |
#函式說明:
|
|
|
4718 |
#將字串中的每個字變成hex的字串陣列
|
|
|
4719 |
#回傳結果:
|
|
|
4720 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4721 |
#$result["function"],當前執行的函式內容.
|
|
|
4722 |
#$result["error"],錯誤訊息陣列.
|
|
|
4723 |
#$result["content"],hex的字串陣列.
|
|
|
4724 |
#必填參數:
|
|
|
4725 |
#$conf["input"],字串,要轉換成bytes陣列的字串.
|
|
|
4726 |
$conf["input"]="";
|
|
|
4727 |
#可省略參數:
|
|
|
4728 |
#無.
|
|
|
4729 |
#參考資料:
|
|
|
4730 |
#無.
|
|
|
4731 |
#備註:
|
|
|
4732 |
#無.
|
| 226 |
liveuser |
4733 |
*/
|
| 3 |
liveuser |
4734 |
public static function str2bytesArray(&$conf){
|
| 226 |
liveuser |
4735 |
|
| 3 |
liveuser |
4736 |
#初始化要回傳的結果
|
|
|
4737 |
$result=array();
|
|
|
4738 |
|
|
|
4739 |
#取得當前執行的函數名稱
|
|
|
4740 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
4741 |
|
| 3 |
liveuser |
4742 |
#初始化儲存bytes陣列
|
|
|
4743 |
$result["content"]=array();
|
|
|
4744 |
|
|
|
4745 |
#如果沒有參數
|
|
|
4746 |
if(func_num_args()==0){
|
| 226 |
liveuser |
4747 |
|
| 3 |
liveuser |
4748 |
#設置執行失敗
|
|
|
4749 |
$result["status"]="false";
|
| 226 |
liveuser |
4750 |
|
| 3 |
liveuser |
4751 |
#設置執行錯誤訊息
|
|
|
4752 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
4753 |
|
| 3 |
liveuser |
4754 |
#回傳結果
|
|
|
4755 |
return $result;
|
| 226 |
liveuser |
4756 |
|
| 3 |
liveuser |
4757 |
}#if end
|
|
|
4758 |
|
|
|
4759 |
#取得參數
|
|
|
4760 |
$result["argu"]=$conf;
|
|
|
4761 |
|
|
|
4762 |
#如果 $conf 不為陣列
|
|
|
4763 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
4764 |
|
| 3 |
liveuser |
4765 |
#設置執行失敗
|
|
|
4766 |
$result["status"]="false";
|
| 226 |
liveuser |
4767 |
|
| 3 |
liveuser |
4768 |
#設置執行錯誤訊息
|
|
|
4769 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
4770 |
|
| 3 |
liveuser |
4771 |
#如果傳入的參數為 null
|
|
|
4772 |
if($conf===null){
|
| 226 |
liveuser |
4773 |
|
| 3 |
liveuser |
4774 |
#設置執行錯誤訊息
|
|
|
4775 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4776 |
|
| 3 |
liveuser |
4777 |
}#if end
|
|
|
4778 |
|
|
|
4779 |
#回傳結果
|
|
|
4780 |
return $result;
|
| 226 |
liveuser |
4781 |
|
| 3 |
liveuser |
4782 |
}#if end
|
| 226 |
liveuser |
4783 |
|
| 3 |
liveuser |
4784 |
#函式說明:
|
|
|
4785 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4786 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4787 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4788 |
#$result["function"],當前執行的函式名稱.
|
|
|
4789 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4790 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4791 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4792 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4793 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4794 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4795 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4796 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4797 |
#必填寫的參數:
|
|
|
4798 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4799 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4800 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4801 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
4802 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4803 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4804 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4805 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4806 |
#可以省略的參數:
|
|
|
4807 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4808 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
4809 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4810 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4811 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4812 |
#$conf["canBeEmpty"]=array();
|
|
|
4813 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4814 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4815 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4816 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
4817 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4818 |
#$conf["skipableVariableType"]=array();
|
|
|
4819 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4820 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4821 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4822 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4823 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4824 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4825 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4826 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4827 |
#參考資料來源:
|
|
|
4828 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4829 |
#建議:
|
|
|
4830 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4831 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4832 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4833 |
|
| 3 |
liveuser |
4834 |
#如果檢查參數失敗
|
|
|
4835 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
4836 |
|
| 3 |
liveuser |
4837 |
#設置執行失敗
|
|
|
4838 |
$result["status"]="false";
|
| 226 |
liveuser |
4839 |
|
| 3 |
liveuser |
4840 |
#設置執行錯誤訊息
|
|
|
4841 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4842 |
|
| 3 |
liveuser |
4843 |
#回傳結果
|
|
|
4844 |
return $result;
|
| 226 |
liveuser |
4845 |
|
| 3 |
liveuser |
4846 |
}#if end
|
| 226 |
liveuser |
4847 |
|
| 3 |
liveuser |
4848 |
#如果檢查參數不通過
|
|
|
4849 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4850 |
|
| 3 |
liveuser |
4851 |
#設置執行失敗
|
|
|
4852 |
$result["status"]="false";
|
| 226 |
liveuser |
4853 |
|
| 3 |
liveuser |
4854 |
#設置執行錯誤訊息
|
|
|
4855 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4856 |
|
| 3 |
liveuser |
4857 |
#回傳結果
|
|
|
4858 |
return $result;
|
| 226 |
liveuser |
4859 |
|
| 3 |
liveuser |
4860 |
}#if end
|
| 226 |
liveuser |
4861 |
|
| 3 |
liveuser |
4862 |
#當字串還有內容
|
|
|
4863 |
while(strlen($conf["input"])>0)
|
|
|
4864 |
{
|
|
|
4865 |
#取得一個字串
|
| 226 |
liveuser |
4866 |
$char=substr($conf["input"],0,1);
|
|
|
4867 |
|
| 3 |
liveuser |
4868 |
#儲存16進位的bytes數字
|
|
|
4869 |
$result["content"][]=strtoupper(sprintf("%02s",(base_convert(ord($char),10,16))));
|
| 226 |
liveuser |
4870 |
|
| 3 |
liveuser |
4871 |
#取得剩下的字串
|
|
|
4872 |
$conf["input"]=substr($conf["input"],1);
|
| 226 |
liveuser |
4873 |
|
| 3 |
liveuser |
4874 |
}#while end
|
| 226 |
liveuser |
4875 |
|
| 3 |
liveuser |
4876 |
#設置執行正常
|
|
|
4877 |
$result["status"]="true";
|
| 226 |
liveuser |
4878 |
|
| 3 |
liveuser |
4879 |
#回傳
|
|
|
4880 |
return $result;
|
| 226 |
liveuser |
4881 |
|
| 3 |
liveuser |
4882 |
}#funcrion str2bytesArray end
|
| 226 |
liveuser |
4883 |
|
| 3 |
liveuser |
4884 |
/*
|
|
|
4885 |
#函式說明:
|
|
|
4886 |
#將字串中的每個字變成hex的字串
|
|
|
4887 |
#回傳結果:
|
|
|
4888 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
4889 |
#$result["function"],當前執行的函式內容.
|
|
|
4890 |
#$result["error"],錯誤訊息陣列.
|
|
|
4891 |
#$result["content"],hex字串.
|
|
|
4892 |
#必填參數:
|
|
|
4893 |
#$conf["input"],字串,要轉換成hex字串的字串.
|
|
|
4894 |
$conf["input"]="";
|
|
|
4895 |
#可省略參數:
|
|
|
4896 |
#無.
|
|
|
4897 |
#參考資料:
|
|
|
4898 |
#無.
|
|
|
4899 |
#備註:
|
|
|
4900 |
#無.
|
| 226 |
liveuser |
4901 |
*/
|
| 3 |
liveuser |
4902 |
public static function str2hexStr(&$conf){
|
| 226 |
liveuser |
4903 |
|
| 3 |
liveuser |
4904 |
#初始化要回傳的結果
|
|
|
4905 |
$result=array();
|
|
|
4906 |
|
|
|
4907 |
#取得當前執行的函數名稱
|
|
|
4908 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
4909 |
|
| 3 |
liveuser |
4910 |
#初始化儲存bytes陣列
|
|
|
4911 |
$result["content"]=array();
|
|
|
4912 |
|
|
|
4913 |
#如果沒有參數
|
|
|
4914 |
if(func_num_args()==0){
|
| 226 |
liveuser |
4915 |
|
| 3 |
liveuser |
4916 |
#設置執行失敗
|
|
|
4917 |
$result["status"]="false";
|
| 226 |
liveuser |
4918 |
|
| 3 |
liveuser |
4919 |
#設置執行錯誤訊息
|
|
|
4920 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
4921 |
|
| 3 |
liveuser |
4922 |
#回傳結果
|
|
|
4923 |
return $result;
|
| 226 |
liveuser |
4924 |
|
| 3 |
liveuser |
4925 |
}#if end
|
|
|
4926 |
|
|
|
4927 |
#取得參數
|
|
|
4928 |
$result["argu"]=$conf;
|
|
|
4929 |
|
|
|
4930 |
#如果 $conf 不為陣列
|
|
|
4931 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
4932 |
|
| 3 |
liveuser |
4933 |
#設置執行失敗
|
|
|
4934 |
$result["status"]="false";
|
| 226 |
liveuser |
4935 |
|
| 3 |
liveuser |
4936 |
#設置執行錯誤訊息
|
|
|
4937 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
4938 |
|
| 3 |
liveuser |
4939 |
#如果傳入的參數為 null
|
|
|
4940 |
if($conf===null){
|
| 226 |
liveuser |
4941 |
|
| 3 |
liveuser |
4942 |
#設置執行錯誤訊息
|
|
|
4943 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4944 |
|
| 3 |
liveuser |
4945 |
}#if end
|
|
|
4946 |
|
|
|
4947 |
#回傳結果
|
|
|
4948 |
return $result;
|
| 226 |
liveuser |
4949 |
|
| 3 |
liveuser |
4950 |
}#if end
|
| 226 |
liveuser |
4951 |
|
| 3 |
liveuser |
4952 |
#函式說明:
|
|
|
4953 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4954 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4955 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4956 |
#$result["function"],當前執行的函式名稱.
|
|
|
4957 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4958 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4959 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4960 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4961 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4962 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4963 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4964 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4965 |
#必填寫的參數:
|
|
|
4966 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4967 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4968 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4969 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
|
|
|
4970 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4971 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
4972 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4973 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4974 |
#可以省略的參數:
|
|
|
4975 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4976 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
4977 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
4978 |
#$conf["canNotBeEmpty"]=array();
|
|
|
4979 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
4980 |
#$conf["canBeEmpty"]=array();
|
|
|
4981 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
4982 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4983 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4984 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
4985 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4986 |
#$conf["skipableVariableType"]=array();
|
|
|
4987 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4988 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
4989 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
4990 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
4991 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
4992 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
4993 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4994 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4995 |
#參考資料來源:
|
|
|
4996 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4997 |
#建議:
|
|
|
4998 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
4999 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5000 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5001 |
|
| 3 |
liveuser |
5002 |
#如果檢查參數失敗
|
|
|
5003 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5004 |
|
| 3 |
liveuser |
5005 |
#設置執行失敗
|
|
|
5006 |
$result["status"]="false";
|
| 226 |
liveuser |
5007 |
|
| 3 |
liveuser |
5008 |
#設置執行錯誤訊息
|
|
|
5009 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5010 |
|
| 3 |
liveuser |
5011 |
#回傳結果
|
|
|
5012 |
return $result;
|
| 226 |
liveuser |
5013 |
|
| 3 |
liveuser |
5014 |
}#if end
|
| 226 |
liveuser |
5015 |
|
| 3 |
liveuser |
5016 |
#如果檢查參數不通過
|
|
|
5017 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
5018 |
|
| 3 |
liveuser |
5019 |
#設置執行失敗
|
|
|
5020 |
$result["status"]="false";
|
| 226 |
liveuser |
5021 |
|
| 3 |
liveuser |
5022 |
#設置執行錯誤訊息
|
|
|
5023 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5024 |
|
| 3 |
liveuser |
5025 |
#回傳結果
|
|
|
5026 |
return $result;
|
| 226 |
liveuser |
5027 |
|
| 3 |
liveuser |
5028 |
}#if end
|
| 226 |
liveuser |
5029 |
|
| 3 |
liveuser |
5030 |
#透過 stringProcess::str2bytesArray 取得 hex字串陣列
|
|
|
5031 |
$conf["stringProcess::str2bytesArray"]["input"]=$conf;
|
|
|
5032 |
$str2bytesArray=stringProcess::str2bytesArray($conf["stringProcess::str2bytesArray"]);
|
|
|
5033 |
unset($conf["stringProcess::str2bytesArray"]);
|
| 226 |
liveuser |
5034 |
|
| 3 |
liveuser |
5035 |
#如果執行失敗
|
|
|
5036 |
if($str2bytesArray["status"]==="false"){
|
| 226 |
liveuser |
5037 |
|
| 3 |
liveuser |
5038 |
#設置執行不正常
|
|
|
5039 |
$result["status"]="false";
|
| 226 |
liveuser |
5040 |
|
| 3 |
liveuser |
5041 |
#設置錯誤訊息
|
|
|
5042 |
$result["error"]=$str2bytesArray;
|
| 226 |
liveuser |
5043 |
|
| 3 |
liveuser |
5044 |
#回傳結果
|
|
|
5045 |
return $resutl;
|
| 226 |
liveuser |
5046 |
|
| 3 |
liveuser |
5047 |
}#if end
|
| 226 |
liveuser |
5048 |
|
| 3 |
liveuser |
5049 |
#函式說明:
|
|
|
5050 |
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
|
|
|
5051 |
#回傳的結果:
|
|
|
5052 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5053 |
#$result["function"],當前執行的function名稱
|
|
|
5054 |
#$result["error"],錯誤訊息陣列.
|
|
|
5055 |
#$result["content"],處理好的字串.
|
|
|
5056 |
#$result["argu"],使用的參數.
|
|
|
5057 |
#必填參數:
|
|
|
5058 |
#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
|
|
|
5059 |
$conf["arrays::arrayToString"]["inputArray"]=$str2bytesArray["content"];
|
|
|
5060 |
#可省略參數:
|
|
|
5061 |
#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
|
|
|
5062 |
#$conf["spiltSymbol"]=";";
|
|
|
5063 |
#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
|
|
|
5064 |
#$conf["skipEnd"]="";
|
|
|
5065 |
#參考資料:
|
|
|
5066 |
#無.
|
|
|
5067 |
#備註:
|
|
|
5068 |
#無.
|
|
|
5069 |
$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
|
|
|
5070 |
unset($conf["arrays::arrayToString"]);
|
| 226 |
liveuser |
5071 |
|
| 3 |
liveuser |
5072 |
#如果執行失敗
|
|
|
5073 |
if($arrayToString["status"]==="false"){
|
| 226 |
liveuser |
5074 |
|
| 3 |
liveuser |
5075 |
#設置執行不正常
|
|
|
5076 |
$result["status"]="false";
|
| 226 |
liveuser |
5077 |
|
| 3 |
liveuser |
5078 |
#設置錯誤訊息
|
|
|
5079 |
$result["error"]=$arrayToString;
|
| 226 |
liveuser |
5080 |
|
| 3 |
liveuser |
5081 |
#回傳結果
|
|
|
5082 |
return $resutl;
|
| 226 |
liveuser |
5083 |
|
| 3 |
liveuser |
5084 |
}#if end
|
| 226 |
liveuser |
5085 |
|
| 3 |
liveuser |
5086 |
#設置執行正常
|
|
|
5087 |
$result["status"]="true";
|
| 226 |
liveuser |
5088 |
|
| 3 |
liveuser |
5089 |
#設置回傳的內容
|
|
|
5090 |
$result["content"]=$arrayToString["content"];
|
| 226 |
liveuser |
5091 |
|
| 3 |
liveuser |
5092 |
#回傳結果
|
|
|
5093 |
return $result;
|
| 226 |
liveuser |
5094 |
|
| 3 |
liveuser |
5095 |
}#function str2hexStr end
|
| 226 |
liveuser |
5096 |
|
| 3 |
liveuser |
5097 |
/*
|
|
|
5098 |
#函式說明:
|
|
|
5099 |
#將bytes數字(16進位)轉換為bit字串(0跟1來表述)
|
|
|
5100 |
#回傳結果:
|
|
|
5101 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5102 |
#$result["function"],當前執行的函式內容.
|
|
|
5103 |
#$result["error"],錯誤訊息陣列.
|
|
|
5104 |
#$result["content"],bit字串(0跟1來表述).
|
|
|
5105 |
#必填參數:
|
|
|
5106 |
#$conf["bytes"],字串,要轉換成bit的bytes數字.
|
|
|
5107 |
$conf["bytes"]="";
|
|
|
5108 |
#可省略參數:
|
|
|
5109 |
#無.
|
|
|
5110 |
#參考資料:
|
|
|
5111 |
#無.
|
|
|
5112 |
#備註:
|
|
|
5113 |
#無.
|
|
|
5114 |
*/
|
|
|
5115 |
public static function bytes2bitString(&$conf){
|
| 226 |
liveuser |
5116 |
|
| 3 |
liveuser |
5117 |
#初始化要回傳的結果
|
|
|
5118 |
$result=array();
|
|
|
5119 |
|
|
|
5120 |
#取得當前執行的函數名稱
|
|
|
5121 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5122 |
|
| 3 |
liveuser |
5123 |
#初始化結果
|
|
|
5124 |
$result["content"]=array();
|
|
|
5125 |
|
|
|
5126 |
#如果沒有參數
|
|
|
5127 |
if(func_num_args()==0){
|
| 226 |
liveuser |
5128 |
|
| 3 |
liveuser |
5129 |
#設置執行失敗
|
|
|
5130 |
$result["status"]="false";
|
| 226 |
liveuser |
5131 |
|
| 3 |
liveuser |
5132 |
#設置執行錯誤訊息
|
|
|
5133 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
5134 |
|
| 3 |
liveuser |
5135 |
#回傳結果
|
|
|
5136 |
return $result;
|
| 226 |
liveuser |
5137 |
|
| 3 |
liveuser |
5138 |
}#if end
|
|
|
5139 |
|
|
|
5140 |
#取得參數
|
|
|
5141 |
$result["argu"]=$conf;
|
|
|
5142 |
|
|
|
5143 |
#如果 $conf 不為陣列
|
|
|
5144 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
5145 |
|
| 3 |
liveuser |
5146 |
#設置執行失敗
|
|
|
5147 |
$result["status"]="false";
|
| 226 |
liveuser |
5148 |
|
| 3 |
liveuser |
5149 |
#設置執行錯誤訊息
|
|
|
5150 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
5151 |
|
| 3 |
liveuser |
5152 |
#如果傳入的參數為 null
|
|
|
5153 |
if($conf===null){
|
| 226 |
liveuser |
5154 |
|
| 3 |
liveuser |
5155 |
#設置執行錯誤訊息
|
|
|
5156 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
5157 |
|
| 3 |
liveuser |
5158 |
}#if end
|
|
|
5159 |
|
|
|
5160 |
#回傳結果
|
|
|
5161 |
return $result;
|
| 226 |
liveuser |
5162 |
|
| 3 |
liveuser |
5163 |
}#if end
|
| 226 |
liveuser |
5164 |
|
| 3 |
liveuser |
5165 |
#函式說明:
|
|
|
5166 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5167 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5168 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5169 |
#$result["function"],當前執行的函式名稱.
|
|
|
5170 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5171 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5172 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5173 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5174 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5175 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5176 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5177 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5178 |
#必填寫的參數:
|
|
|
5179 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5180 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5181 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5182 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("bytes");
|
|
|
5183 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
5184 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5185 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5186 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5187 |
#可以省略的參數:
|
|
|
5188 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5189 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="true";
|
|
|
5190 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5191 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5192 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5193 |
#$conf["canBeEmpty"]=array();
|
|
|
5194 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5195 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5196 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5197 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
5198 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
5199 |
#$conf["skipableVariableType"]=array();
|
|
|
5200 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5201 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5202 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5203 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5204 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5205 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5206 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5207 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5208 |
#參考資料來源:
|
|
|
5209 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5210 |
#建議:
|
|
|
5211 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
5212 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5213 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5214 |
|
| 3 |
liveuser |
5215 |
#如果檢查參數失敗
|
|
|
5216 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5217 |
|
| 3 |
liveuser |
5218 |
#設置執行失敗
|
|
|
5219 |
$result["status"]="false";
|
| 226 |
liveuser |
5220 |
|
| 3 |
liveuser |
5221 |
#設置執行錯誤訊息
|
|
|
5222 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5223 |
|
| 3 |
liveuser |
5224 |
#回傳結果
|
|
|
5225 |
return $result;
|
| 226 |
liveuser |
5226 |
|
| 3 |
liveuser |
5227 |
}#if end
|
| 226 |
liveuser |
5228 |
|
| 3 |
liveuser |
5229 |
#如果檢查參數不通過
|
|
|
5230 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
5231 |
|
| 3 |
liveuser |
5232 |
#設置執行失敗
|
|
|
5233 |
$result["status"]="false";
|
| 226 |
liveuser |
5234 |
|
| 3 |
liveuser |
5235 |
#設置執行錯誤訊息
|
|
|
5236 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5237 |
|
| 3 |
liveuser |
5238 |
#回傳結果
|
|
|
5239 |
return $result;
|
| 226 |
liveuser |
5240 |
|
| 3 |
liveuser |
5241 |
}#if end
|
| 226 |
liveuser |
5242 |
|
| 3 |
liveuser |
5243 |
#儲存2進位數值
|
|
|
5244 |
$result["content"]=sprintf("%08s",base_convert($conf["bytes"],16,2));
|
| 226 |
liveuser |
5245 |
|
| 3 |
liveuser |
5246 |
#設置執行正常
|
|
|
5247 |
$result["status"]="true";
|
| 226 |
liveuser |
5248 |
|
| 3 |
liveuser |
5249 |
#回傳
|
|
|
5250 |
return $result;
|
| 226 |
liveuser |
5251 |
|
| 3 |
liveuser |
5252 |
}#function bytes2bitString end
|
| 226 |
liveuser |
5253 |
|
| 3 |
liveuser |
5254 |
/*
|
|
|
5255 |
#函式說明:
|
|
|
5256 |
#將2進位的8位數字字串,變成bytes字串.
|
|
|
5257 |
#回傳結果:
|
|
|
5258 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5259 |
#$result["function"],當前執行的函式內容.
|
|
|
5260 |
#$result["error"],錯誤訊息陣列.
|
|
|
5261 |
#$result["content"],bytes字串,亦即其代表的一個字.
|
|
|
5262 |
#必填參數:
|
|
|
5263 |
#$conf["8bits"],字串,要轉換成byte字串的bit數字字串,小於8位會於前頭補0,若非2進位的bit數字字串,則會報錯.
|
|
|
5264 |
$conf["8bits"]="00000000";
|
|
|
5265 |
#可省略參數:
|
|
|
5266 |
#無.
|
|
|
5267 |
#參考資料:
|
|
|
5268 |
#無.
|
|
|
5269 |
#備註:
|
|
|
5270 |
#無.
|
|
|
5271 |
*/
|
|
|
5272 |
public static function bit2byteStr($conf){
|
| 226 |
liveuser |
5273 |
|
| 3 |
liveuser |
5274 |
#初始化要回傳的結果
|
|
|
5275 |
$result=array();
|
|
|
5276 |
|
|
|
5277 |
#設置當其函數名稱
|
|
|
5278 |
$result["function"]=__FUNCTION__;
|
|
|
5279 |
|
|
|
5280 |
#如果 $conf 不為陣列
|
|
|
5281 |
if(gettype($conf)!="array"){
|
|
|
5282 |
|
|
|
5283 |
#設置執行失敗
|
|
|
5284 |
$result["status"]="false";
|
|
|
5285 |
|
|
|
5286 |
#設置執行錯誤訊息
|
|
|
5287 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5288 |
|
|
|
5289 |
#如果傳入的參數為 null
|
|
|
5290 |
if($conf==null){
|
|
|
5291 |
|
|
|
5292 |
#設置執行錯誤訊息
|
|
|
5293 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5294 |
|
|
|
5295 |
}#if end
|
|
|
5296 |
|
|
|
5297 |
#函式說明:
|
|
|
5298 |
#取得簡單的錯誤訊息
|
|
|
5299 |
#回傳結果:
|
|
|
5300 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5301 |
#$result["content"],結果.
|
|
|
5302 |
#$result["function"],當前執行的函數
|
|
|
5303 |
#$result["error"],涵式錯誤訊息陣列
|
|
|
5304 |
#必填參數:
|
|
|
5305 |
$conf["variableCheck::getSimpleError"]=array();
|
|
|
5306 |
#$conf["error"],陣列,要處理的變數.
|
|
|
5307 |
$conf["variableCheck::getSimpleError"]["error"]=$result;
|
|
|
5308 |
#可省略參數:
|
|
|
5309 |
#無
|
|
|
5310 |
#參考資料:
|
|
|
5311 |
#無.
|
|
|
5312 |
#備註:
|
|
|
5313 |
#無.
|
|
|
5314 |
$getSimpleError=variableCheck::getSimpleError($conf["variableCheck::getSimpleError"]);
|
|
|
5315 |
unset($conf["variableCheck::getSimpleError"]);
|
|
|
5316 |
|
|
|
5317 |
#如果執行失敗
|
|
|
5318 |
if($getSimpleError["status"]==="false"){
|
| 226 |
liveuser |
5319 |
|
| 3 |
liveuser |
5320 |
#設置執行錯誤訊息
|
|
|
5321 |
$result["error"][]=$getSimpleError;
|
| 226 |
liveuser |
5322 |
|
| 3 |
liveuser |
5323 |
#回傳結果
|
|
|
5324 |
return $result;
|
|
|
5325 |
|
|
|
5326 |
}#if end
|
|
|
5327 |
|
|
|
5328 |
#設置 $simpleError
|
|
|
5329 |
$result["simpleError"]=$getSimpleError["content"];
|
|
|
5330 |
|
|
|
5331 |
#回傳結果
|
|
|
5332 |
return $result;
|
|
|
5333 |
|
|
|
5334 |
}#if end
|
|
|
5335 |
|
|
|
5336 |
#設置放置的參數
|
|
|
5337 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
5338 |
|
| 3 |
liveuser |
5339 |
#函式說明:
|
|
|
5340 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
5341 |
#回傳結果:
|
|
|
5342 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5343 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
5344 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
5345 |
#$result["function"],當前執行的函式名稱.
|
|
|
5346 |
#$result["argu"],設置給予的參數.
|
|
|
5347 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5348 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5349 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5350 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5351 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5352 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5353 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5354 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5355 |
#必填參數:
|
|
|
5356 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5357 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5358 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5359 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5360 |
#可省略參數:
|
|
|
5361 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5362 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("8bits");
|
|
|
5363 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
5364 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
5365 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5366 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
5367 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5368 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5369 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5370 |
#$conf["canBeEmpty"]=array();
|
|
|
5371 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5372 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5373 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5374 |
#$conf["skipableVariableName"]=array();
|
|
|
5375 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5376 |
#$conf["skipableVariableType"]=array();
|
|
|
5377 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5378 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5379 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5380 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5381 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5382 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5383 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5384 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5385 |
#參考資料:
|
|
|
5386 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5387 |
#備註:
|
|
|
5388 |
#無.
|
|
|
5389 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5390 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5391 |
|
| 3 |
liveuser |
5392 |
#如果檢查參數失敗
|
|
|
5393 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5394 |
|
| 3 |
liveuser |
5395 |
#設置執行失敗
|
|
|
5396 |
$result["status"]="false";
|
| 226 |
liveuser |
5397 |
|
| 3 |
liveuser |
5398 |
#設置錯誤訊息陣列
|
|
|
5399 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5400 |
|
| 3 |
liveuser |
5401 |
#回傳結果
|
|
|
5402 |
return $result;
|
| 226 |
liveuser |
5403 |
|
| 3 |
liveuser |
5404 |
}#if end
|
| 226 |
liveuser |
5405 |
|
| 3 |
liveuser |
5406 |
#如果檢查參數不通過
|
|
|
5407 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5408 |
|
| 3 |
liveuser |
5409 |
#設置執行失敗
|
|
|
5410 |
$result["status"]="false";
|
| 226 |
liveuser |
5411 |
|
| 3 |
liveuser |
5412 |
#設置錯誤訊息陣列
|
|
|
5413 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5414 |
|
| 3 |
liveuser |
5415 |
#回傳結果
|
|
|
5416 |
return $result;
|
| 226 |
liveuser |
5417 |
|
| 3 |
liveuser |
5418 |
}#if end
|
| 226 |
liveuser |
5419 |
|
| 3 |
liveuser |
5420 |
#如果長度大於8
|
|
|
5421 |
if(strlen($conf["8bits"])>8){
|
| 226 |
liveuser |
5422 |
|
| 3 |
liveuser |
5423 |
#設置執行失敗
|
|
|
5424 |
$result["status"]="false";
|
| 226 |
liveuser |
5425 |
|
| 3 |
liveuser |
5426 |
#設置錯誤訊息陣列
|
|
|
5427 |
$result["error"][]="請確認為8bits字串";
|
| 226 |
liveuser |
5428 |
|
| 3 |
liveuser |
5429 |
#回傳結果
|
|
|
5430 |
return $result;
|
| 226 |
liveuser |
5431 |
|
| 3 |
liveuser |
5432 |
}#if end
|
| 226 |
liveuser |
5433 |
|
| 3 |
liveuser |
5434 |
#取得結果字串
|
|
|
5435 |
$result["content"]=chr(base_convert($conf["8bits"],2,10));
|
| 226 |
liveuser |
5436 |
|
| 3 |
liveuser |
5437 |
#設置執行正常
|
|
|
5438 |
$result["status"]="true";
|
| 226 |
liveuser |
5439 |
|
| 3 |
liveuser |
5440 |
#回傳結果
|
|
|
5441 |
return $result;
|
| 226 |
liveuser |
5442 |
|
| 3 |
liveuser |
5443 |
}#function bit2bytes end
|
| 226 |
liveuser |
5444 |
|
| 3 |
liveuser |
5445 |
/*
|
|
|
5446 |
#函式說明:
|
|
|
5447 |
#隨機產生任意byte(s)組成的字串.
|
|
|
5448 |
#回傳結果:
|
|
|
5449 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
|
|
5450 |
#$result["function"],當前執行的函式內容.
|
|
|
5451 |
#$result["error"],錯誤訊息陣列.
|
|
|
5452 |
#$result["content"],用字串來表示的byte(s).
|
|
|
5453 |
#必填參數:
|
|
|
5454 |
#無.
|
|
|
5455 |
#可省略參數:
|
|
|
5456 |
#$conf["length"],字串,要產生多少bytes的字串,預設為1.
|
|
|
5457 |
#$conf["length"]="1";
|
|
|
5458 |
#參考資料:
|
|
|
5459 |
#無.
|
|
|
5460 |
#備註:
|
|
|
5461 |
#無.
|
|
|
5462 |
*/
|
|
|
5463 |
public static function randomByte(&$conf){
|
| 226 |
liveuser |
5464 |
|
| 3 |
liveuser |
5465 |
#初始化要回傳的結果
|
|
|
5466 |
$result=array();
|
|
|
5467 |
|
|
|
5468 |
#取得當前執行的函數名稱
|
|
|
5469 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5470 |
|
| 3 |
liveuser |
5471 |
#取得參數
|
|
|
5472 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
5473 |
|
| 3 |
liveuser |
5474 |
#如果 $conf 不為陣列
|
|
|
5475 |
if(gettype($conf)!="array"){
|
|
|
5476 |
|
|
|
5477 |
#設置執行失敗
|
|
|
5478 |
$result["status"]="false";
|
|
|
5479 |
|
|
|
5480 |
#設置執行錯誤訊息
|
|
|
5481 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5482 |
|
|
|
5483 |
#如果傳入的參數為 null
|
|
|
5484 |
if(is_null($conf)){
|
|
|
5485 |
|
|
|
5486 |
#設置執行錯誤訊息
|
|
|
5487 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5488 |
|
|
|
5489 |
}#if end
|
|
|
5490 |
|
|
|
5491 |
#回傳結果
|
|
|
5492 |
return $result;
|
|
|
5493 |
|
|
|
5494 |
}#if end
|
| 226 |
liveuser |
5495 |
|
| 3 |
liveuser |
5496 |
#函式說明:
|
|
|
5497 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
5498 |
#回傳結果:
|
|
|
5499 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5500 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
5501 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
5502 |
#$result["function"],當前執行的函式名稱.
|
|
|
5503 |
#$result["argu"],設置給予的參數.
|
|
|
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["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5516 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5517 |
#可省略參數:
|
|
|
5518 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5519 |
#$conf["mustBeFilledVariableName"]=array();
|
|
|
5520 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
5521 |
#$conf["mustBeFilledVariableType"]=array();
|
|
|
5522 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5523 |
#$conf["canBeEmptyString"]="false";
|
|
|
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["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("length");
|
|
|
5530 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5531 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("length");
|
|
|
5532 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5533 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
5534 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5535 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("1");
|
|
|
5536 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5537 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5538 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5539 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5540 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
5541 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
5542 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5543 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5544 |
#參考資料:
|
|
|
5545 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5546 |
#備註:
|
|
|
5547 |
#無.
|
|
|
5548 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5549 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5550 |
|
| 3 |
liveuser |
5551 |
#如果檢查參數失敗
|
|
|
5552 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5553 |
|
| 3 |
liveuser |
5554 |
#設置執行失敗
|
|
|
5555 |
$result["status"]="false";
|
| 226 |
liveuser |
5556 |
|
| 3 |
liveuser |
5557 |
#設置錯誤訊息陣列
|
|
|
5558 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5559 |
|
| 3 |
liveuser |
5560 |
#回傳結果
|
|
|
5561 |
return $result;
|
| 226 |
liveuser |
5562 |
|
| 3 |
liveuser |
5563 |
}#if end
|
| 226 |
liveuser |
5564 |
|
| 3 |
liveuser |
5565 |
#如果檢查參數不通過
|
|
|
5566 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5567 |
|
| 3 |
liveuser |
5568 |
#設置執行失敗
|
|
|
5569 |
$result["status"]="false";
|
| 226 |
liveuser |
5570 |
|
| 3 |
liveuser |
5571 |
#設置錯誤訊息陣列
|
|
|
5572 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5573 |
|
| 3 |
liveuser |
5574 |
#回傳結果
|
|
|
5575 |
return $result;
|
| 226 |
liveuser |
5576 |
|
| 3 |
liveuser |
5577 |
}#if end
|
| 226 |
liveuser |
5578 |
|
| 3 |
liveuser |
5579 |
#初始化儲存用字串來表示的byte(s).
|
|
|
5580 |
$result["content"]="";
|
| 226 |
liveuser |
5581 |
|
| 3 |
liveuser |
5582 |
#要多少bytes就跑幾次
|
|
|
5583 |
for($i=0;$i<$conf["length"];$i++){
|
| 226 |
liveuser |
5584 |
|
| 3 |
liveuser |
5585 |
#暫存byte
|
|
|
5586 |
$byte="";
|
| 226 |
liveuser |
5587 |
|
| 3 |
liveuser |
5588 |
#隨機產生該byte開始bit不為0的位置
|
|
|
5589 |
$bitNotZeroAddr=\rand(0,7);
|
| 226 |
liveuser |
5590 |
|
| 3 |
liveuser |
5591 |
#每個bit都跑一次
|
|
|
5592 |
for($j=0;$j<8;$j++){
|
| 226 |
liveuser |
5593 |
|
| 3 |
liveuser |
5594 |
#如果還沒開始有資料
|
|
|
5595 |
if($j<$bitNotZeroAddr){
|
| 226 |
liveuser |
5596 |
|
| 3 |
liveuser |
5597 |
#加0
|
|
|
5598 |
$byte=$byte."0";
|
| 226 |
liveuser |
5599 |
|
| 3 |
liveuser |
5600 |
#下一個迴圈
|
|
|
5601 |
continue;
|
| 226 |
liveuser |
5602 |
|
| 3 |
liveuser |
5603 |
}#if end
|
| 226 |
liveuser |
5604 |
|
| 3 |
liveuser |
5605 |
#隨機產生bit
|
|
|
5606 |
$bit=\rand(0,1);
|
| 226 |
liveuser |
5607 |
|
| 3 |
liveuser |
5608 |
#加bit
|
|
|
5609 |
$byte=$byte.(string)($bit);
|
| 226 |
liveuser |
5610 |
|
| 3 |
liveuser |
5611 |
}#for end
|
| 226 |
liveuser |
5612 |
|
| 3 |
liveuser |
5613 |
#用字串來表示byte
|
|
|
5614 |
$byte=chr(base_convert($byte,2,10));
|
| 226 |
liveuser |
5615 |
|
| 3 |
liveuser |
5616 |
#串接byte
|
|
|
5617 |
$result["content"]=$result["content"].$byte;
|
| 226 |
liveuser |
5618 |
|
| 3 |
liveuser |
5619 |
}#for end
|
| 226 |
liveuser |
5620 |
|
| 3 |
liveuser |
5621 |
#設置執行正常
|
|
|
5622 |
$result["status"]="true";
|
| 226 |
liveuser |
5623 |
|
| 3 |
liveuser |
5624 |
#回傳結果
|
|
|
5625 |
return $result;
|
| 226 |
liveuser |
5626 |
|
| 3 |
liveuser |
5627 |
}#function randomByte end
|
| 226 |
liveuser |
5628 |
|
| 3 |
liveuser |
5629 |
/*
|
|
|
5630 |
#函式說明:
|
|
|
5631 |
#判斷字串是否一定需要經過escapeshellarg才能為單一shell參數,並回傳可以成為單一shell參數的結果.
|
|
|
5632 |
#回傳結果:
|
|
|
5633 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5634 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5635 |
#$result["function"],當前執行的函式名稱.
|
|
|
5636 |
#$result["argu"],使用的參數.
|
|
|
5637 |
#$result["content"],字串,單一shell參數.
|
|
|
5638 |
#$result["required"],字串,"true"代表content為 escape後的結果;反之為"false".
|
|
|
5639 |
#$result["urlEncodeStr"],字串,未被escape過的單一shell參數被url encode後的結果.
|
|
|
5640 |
#必填參數:
|
|
|
5641 |
#$conf["str"],字串,認為要為單一 shell參數的字串.
|
|
|
5642 |
#$conf["str"]="";
|
|
|
5643 |
#可省略參數:
|
|
|
5644 |
#無.
|
|
|
5645 |
#參考資料:
|
|
|
5646 |
#無.
|
|
|
5647 |
#備註:
|
|
|
5648 |
#無.
|
|
|
5649 |
*/
|
|
|
5650 |
public static function toSingleShellArg(&$conf){
|
| 226 |
liveuser |
5651 |
|
| 3 |
liveuser |
5652 |
#初始化要回傳的結果
|
|
|
5653 |
$result=array();
|
|
|
5654 |
|
|
|
5655 |
#取得當前執行的函數名稱
|
|
|
5656 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5657 |
|
| 3 |
liveuser |
5658 |
#取得參數
|
|
|
5659 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
5660 |
|
| 3 |
liveuser |
5661 |
#如果 $conf 不為陣列
|
|
|
5662 |
if(gettype($conf)!="array"){
|
|
|
5663 |
|
|
|
5664 |
#設置執行失敗
|
|
|
5665 |
$result["status"]="false";
|
|
|
5666 |
|
|
|
5667 |
#設置執行錯誤訊息
|
|
|
5668 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5669 |
|
|
|
5670 |
#如果傳入的參數為 null
|
|
|
5671 |
if(is_null($conf)){
|
|
|
5672 |
|
|
|
5673 |
#設置執行錯誤訊息
|
|
|
5674 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
5675 |
|
|
|
5676 |
}#if end
|
|
|
5677 |
|
|
|
5678 |
#回傳結果
|
|
|
5679 |
return $result;
|
|
|
5680 |
|
|
|
5681 |
}#if end
|
| 226 |
liveuser |
5682 |
|
| 3 |
liveuser |
5683 |
#檢查參數
|
|
|
5684 |
#函式說明:
|
|
|
5685 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
|
|
5686 |
#回傳結果:
|
|
|
5687 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5688 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
5689 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
5690 |
#$result["function"],當前執行的函式名稱.
|
|
|
5691 |
#$result["argu"],設置給予的參數.
|
|
|
5692 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5693 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5694 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5695 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5696 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
5697 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
5698 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
5699 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
5700 |
#必填參數:
|
|
|
5701 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 220 |
liveuser |
5702 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
5703 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
| 220 |
liveuser |
5704 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
| 3 |
liveuser |
5705 |
#可省略參數:
|
|
|
5706 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
| 220 |
liveuser |
5707 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("str");
|
| 3 |
liveuser |
5708 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
| 220 |
liveuser |
5709 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
| 3 |
liveuser |
5710 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
5711 |
#$conf["canBeEmptyString"]="false";
|
|
|
5712 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
5713 |
#$conf["canNotBeEmpty"]=array();
|
|
|
5714 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
5715 |
#$conf["canBeEmpty"]=array();
|
|
|
5716 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
5717 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
5718 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5719 |
#$conf["skipableVariableName"]=array();
|
|
|
5720 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
5721 |
#$conf["skipableVariableType"]=array();
|
|
|
5722 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5723 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
5724 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
5725 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
5726 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
5727 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
5728 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
5729 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
5730 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5731 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
5732 |
#參考資料:
|
|
|
5733 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
5734 |
#備註:
|
|
|
5735 |
#無.
|
| 220 |
liveuser |
5736 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 3 |
liveuser |
5737 |
unset($conf["variable::checkArguments"]);
|
| 226 |
liveuser |
5738 |
|
| 3 |
liveuser |
5739 |
#如果檢查參數失敗
|
|
|
5740 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
5741 |
|
| 3 |
liveuser |
5742 |
#設置執行失敗
|
|
|
5743 |
$result["status"]="false";
|
| 226 |
liveuser |
5744 |
|
| 3 |
liveuser |
5745 |
#設置錯誤訊息陣列
|
|
|
5746 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5747 |
|
| 3 |
liveuser |
5748 |
#回傳結果
|
|
|
5749 |
return $result;
|
| 226 |
liveuser |
5750 |
|
| 3 |
liveuser |
5751 |
}#if end
|
| 226 |
liveuser |
5752 |
|
| 3 |
liveuser |
5753 |
#如果檢查參數不通過
|
| 220 |
liveuser |
5754 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
5755 |
|
| 3 |
liveuser |
5756 |
#設置執行失敗
|
|
|
5757 |
$result["status"]="false";
|
| 226 |
liveuser |
5758 |
|
| 3 |
liveuser |
5759 |
#設置錯誤訊息陣列
|
|
|
5760 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5761 |
|
| 3 |
liveuser |
5762 |
#回傳結果
|
|
|
5763 |
return $result;
|
| 226 |
liveuser |
5764 |
|
| 3 |
liveuser |
5765 |
}#if end
|
| 226 |
liveuser |
5766 |
|
| 3 |
liveuser |
5767 |
#取得 str 的 bytes 數
|
|
|
5768 |
$strLength=strlen($conf["str"]);
|
| 226 |
liveuser |
5769 |
|
| 3 |
liveuser |
5770 |
#初始化 url encode 後的 str 參數
|
|
|
5771 |
$result["urlEncodeStr"]="";
|
| 226 |
liveuser |
5772 |
|
| 3 |
liveuser |
5773 |
#如果不是空字串
|
|
|
5774 |
if($strLength!==0){
|
| 226 |
liveuser |
5775 |
|
| 220 |
liveuser |
5776 |
#函式說明:
|
|
|
5777 |
#將檔案目錄的絕對位置中的 "../" 剔除變成直觀的路徑.
|
|
|
5778 |
#回傳結果:
|
|
|
5779 |
#$result["status"],執行是否成功,"true"代表執行成功,"false"代表執行失敗.
|
|
|
5780 |
#$result["function"],當前執行的函數.
|
|
|
5781 |
#$result["error"],錯誤訊息陣列.
|
|
|
5782 |
#$result["argu"],使用者參數.
|
|
|
5783 |
#$result["changedPath"],處理完後回傳的目錄字串.
|
|
|
5784 |
#$result["oriPath"],原始的路徑字串
|
|
|
5785 |
#必填參數:
|
|
|
5786 |
#$conf["dirStr"],字串,要處理的檔案目錄字串.
|
|
|
5787 |
$conf["stringProcess::changeDirByDotDotSolidus"]["dirStr"]=pathinfo(__FILE__)["dirname"]."/../../bin/parse";
|
|
|
5788 |
#可省略參數:
|
|
|
5789 |
#無.
|
|
|
5790 |
#參考資料:
|
|
|
5791 |
#無.
|
|
|
5792 |
#備註:
|
|
|
5793 |
#考慮用realpath取代
|
|
|
5794 |
$changeDirByDotDotSolidus=stringProcess::changeDirByDotDotSolidus($conf["stringProcess::changeDirByDotDotSolidus"]);
|
|
|
5795 |
unset($conf["stringProcess::changeDirByDotDotSolidus"]);
|
| 226 |
liveuser |
5796 |
|
| 220 |
liveuser |
5797 |
#如果檢查參數失敗
|
|
|
5798 |
if($changeDirByDotDotSolidus["status"]==="false"){
|
| 226 |
liveuser |
5799 |
|
| 220 |
liveuser |
5800 |
#設置執行失敗
|
|
|
5801 |
$result["status"]="false";
|
| 226 |
liveuser |
5802 |
|
| 220 |
liveuser |
5803 |
#設置錯誤訊息陣列
|
|
|
5804 |
$result["error"]=$changeDirByDotDotSolidus;
|
| 226 |
liveuser |
5805 |
|
| 220 |
liveuser |
5806 |
#回傳結果
|
|
|
5807 |
return $result;
|
| 226 |
liveuser |
5808 |
|
| 220 |
liveuser |
5809 |
}#if end
|
| 226 |
liveuser |
5810 |
|
|
|
5811 |
#設置要執行的指令
|
| 220 |
liveuser |
5812 |
$cmd=escapeshellarg($changeDirByDotDotSolidus["changedPath"])." ".$conf["str"];
|
| 226 |
liveuser |
5813 |
|
| 3 |
liveuser |
5814 |
#執行指令
|
|
|
5815 |
exec($cmd,$output,$status);
|
| 226 |
liveuser |
5816 |
|
| 3 |
liveuser |
5817 |
#如果執行失敗
|
|
|
5818 |
if($status!==0){
|
| 226 |
liveuser |
5819 |
|
| 3 |
liveuser |
5820 |
#設置執行失敗
|
|
|
5821 |
$result["status"]="false";
|
| 226 |
liveuser |
5822 |
|
| 3 |
liveuser |
5823 |
#設置錯誤訊息陣列
|
|
|
5824 |
$result["error"][]="run command(".$cmd.") failed!";
|
| 226 |
liveuser |
5825 |
|
| 3 |
liveuser |
5826 |
#回傳結果
|
|
|
5827 |
return $result;
|
| 226 |
liveuser |
5828 |
|
| 3 |
liveuser |
5829 |
}#if end
|
| 226 |
liveuser |
5830 |
|
| 3 |
liveuser |
5831 |
#如果沒有輸出
|
|
|
5832 |
if(count($output)<1){
|
| 226 |
liveuser |
5833 |
|
| 3 |
liveuser |
5834 |
#設置執行失敗
|
|
|
5835 |
$result["status"]="false";
|
| 226 |
liveuser |
5836 |
|
| 3 |
liveuser |
5837 |
#設置錯誤訊息陣列
|
|
|
5838 |
$result["error"][]="no output from command(".$cmd.")";
|
| 226 |
liveuser |
5839 |
|
| 3 |
liveuser |
5840 |
#回傳結果
|
|
|
5841 |
return $result;
|
| 226 |
liveuser |
5842 |
|
| 3 |
liveuser |
5843 |
}#if end
|
| 226 |
liveuser |
5844 |
|
| 3 |
liveuser |
5845 |
#如果輸出不是 json
|
|
|
5846 |
if(json_validate($output[0])===false){
|
| 226 |
liveuser |
5847 |
|
| 3 |
liveuser |
5848 |
#設置執行失敗
|
|
|
5849 |
$result["status"]="false";
|
| 226 |
liveuser |
5850 |
|
| 3 |
liveuser |
5851 |
#設置錯誤訊息陣列
|
|
|
5852 |
$result["error"][]="output from command(".$cmd.") is not json";
|
| 226 |
liveuser |
5853 |
|
| 3 |
liveuser |
5854 |
#回傳結果
|
|
|
5855 |
return $result;
|
| 226 |
liveuser |
5856 |
|
| 3 |
liveuser |
5857 |
}#if end
|
| 226 |
liveuser |
5858 |
|
| 3 |
liveuser |
5859 |
#array of json decode
|
|
|
5860 |
$resArray=(array)(json_decode($output[0]));
|
| 226 |
liveuser |
5861 |
|
| 3 |
liveuser |
5862 |
#如果解析出來的元素數量不為2
|
|
|
5863 |
if(count($resArray)!==2){
|
| 226 |
liveuser |
5864 |
|
| 3 |
liveuser |
5865 |
#設置需要 escape
|
|
|
5866 |
$result["required"]="true";
|
| 226 |
liveuser |
5867 |
|
| 3 |
liveuser |
5868 |
#設置 content 為原始內容
|
|
|
5869 |
$result["content"]=escapeshellarg($conf["str"]);
|
| 226 |
liveuser |
5870 |
|
| 42 |
liveuser |
5871 |
#設置url encode後的內容
|
|
|
5872 |
$result["urlEncodeStr"]=urlencode($conf["str"]);
|
| 226 |
liveuser |
5873 |
|
| 3 |
liveuser |
5874 |
#設置執行正常
|
|
|
5875 |
$result["status"]="true";
|
| 226 |
liveuser |
5876 |
|
| 3 |
liveuser |
5877 |
#回傳結果
|
|
|
5878 |
return $result;
|
| 226 |
liveuser |
5879 |
|
| 3 |
liveuser |
5880 |
}#if end
|
| 226 |
liveuser |
5881 |
|
| 3 |
liveuser |
5882 |
#反之,有被解析成單一 shell參數
|
|
|
5883 |
else{
|
|
|
5884 |
|
|
|
5885 |
#如果開頭跟結尾是"'"
|
|
|
5886 |
if( $conf["str"][0]==="'" && $conf["str"][$strLength-1]==="'"){
|
| 226 |
liveuser |
5887 |
|
| 3 |
liveuser |
5888 |
#剔除前面的"'"
|
|
|
5889 |
$altStr=substr($conf["str"],1);
|
| 226 |
liveuser |
5890 |
|
| 3 |
liveuser |
5891 |
#剔除後面的"'"
|
|
|
5892 |
$altStr=substr($altStr,0,strlen($altStr)-1);
|
| 226 |
liveuser |
5893 |
|
|
|
5894 |
#設置要執行的指令
|
| 3 |
liveuser |
5895 |
$cmd=escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../bin/parse")." ".$altStr;
|
| 226 |
liveuser |
5896 |
|
| 3 |
liveuser |
5897 |
#執行指令
|
|
|
5898 |
exec($cmd,$output,$status);
|
| 226 |
liveuser |
5899 |
|
| 3 |
liveuser |
5900 |
#如果執行失敗
|
|
|
5901 |
if($status!==0){
|
| 226 |
liveuser |
5902 |
|
| 3 |
liveuser |
5903 |
#設置執行失敗
|
|
|
5904 |
$result["status"]="false";
|
| 226 |
liveuser |
5905 |
|
| 3 |
liveuser |
5906 |
#設置錯誤訊息陣列
|
|
|
5907 |
$result["error"][]="run command(".$cmd.") failed!";
|
| 226 |
liveuser |
5908 |
|
| 220 |
liveuser |
5909 |
#設置錯誤訊息陣列
|
|
|
5910 |
$result["error"][]="output:".print_r($output,true);
|
| 226 |
liveuser |
5911 |
|
| 3 |
liveuser |
5912 |
#回傳結果
|
|
|
5913 |
return $result;
|
| 226 |
liveuser |
5914 |
|
| 3 |
liveuser |
5915 |
}#if end
|
| 226 |
liveuser |
5916 |
|
| 3 |
liveuser |
5917 |
#如果沒有輸出
|
|
|
5918 |
if(count($output)<1){
|
| 226 |
liveuser |
5919 |
|
| 3 |
liveuser |
5920 |
#設置執行失敗
|
|
|
5921 |
$result["status"]="false";
|
| 226 |
liveuser |
5922 |
|
| 3 |
liveuser |
5923 |
#設置錯誤訊息陣列
|
|
|
5924 |
$result["error"][]="no output from command(".$cmd.")";
|
| 226 |
liveuser |
5925 |
|
| 3 |
liveuser |
5926 |
#回傳結果
|
|
|
5927 |
return $result;
|
| 226 |
liveuser |
5928 |
|
| 3 |
liveuser |
5929 |
}#if end
|
| 226 |
liveuser |
5930 |
|
| 3 |
liveuser |
5931 |
#如果輸出不是 json
|
|
|
5932 |
if(json_validate($output[0])===false){
|
| 226 |
liveuser |
5933 |
|
| 3 |
liveuser |
5934 |
#設置執行失敗
|
|
|
5935 |
$result["status"]="false";
|
| 226 |
liveuser |
5936 |
|
| 3 |
liveuser |
5937 |
#設置錯誤訊息陣列
|
|
|
5938 |
$result["error"][]="output from command(".$cmd.") is not json";
|
| 226 |
liveuser |
5939 |
|
| 3 |
liveuser |
5940 |
#回傳結果
|
|
|
5941 |
return $result;
|
| 226 |
liveuser |
5942 |
|
| 3 |
liveuser |
5943 |
}#if end
|
| 226 |
liveuser |
5944 |
|
| 3 |
liveuser |
5945 |
#array of json decode
|
|
|
5946 |
$resArray=(array)(json_decode($output[0]));
|
| 226 |
liveuser |
5947 |
|
| 3 |
liveuser |
5948 |
#如果解析出來的元素數量不為2
|
|
|
5949 |
if(count($resArray)!==2){
|
| 226 |
liveuser |
5950 |
|
| 3 |
liveuser |
5951 |
#設置需要 escape
|
|
|
5952 |
$result["required"]="true";
|
| 226 |
liveuser |
5953 |
|
| 3 |
liveuser |
5954 |
#設置 content 為原始內容
|
|
|
5955 |
$result["content"]=$conf["str"];
|
| 226 |
liveuser |
5956 |
|
| 3 |
liveuser |
5957 |
#設置取得 shell arg 的指令
|
|
|
5958 |
$cmd=escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../bin/parse")." ".$result["content"];
|
| 226 |
liveuser |
5959 |
|
| 3 |
liveuser |
5960 |
#初始化輸出
|
|
|
5961 |
$output=array();
|
| 226 |
liveuser |
5962 |
|
| 3 |
liveuser |
5963 |
#執行指令
|
|
|
5964 |
exec($cmd,$output,$status);
|
| 226 |
liveuser |
5965 |
|
| 3 |
liveuser |
5966 |
#如果執行失敗
|
|
|
5967 |
if($status!==0){
|
| 226 |
liveuser |
5968 |
|
| 3 |
liveuser |
5969 |
#設置執行失敗
|
|
|
5970 |
$result["status"]="false";
|
| 226 |
liveuser |
5971 |
|
| 3 |
liveuser |
5972 |
#設置錯誤訊息陣列
|
|
|
5973 |
$result["error"][]="run command(".$cmd.") failed!";
|
| 226 |
liveuser |
5974 |
|
| 3 |
liveuser |
5975 |
#回傳結果
|
|
|
5976 |
return $result;
|
| 226 |
liveuser |
5977 |
|
| 3 |
liveuser |
5978 |
}#if end
|
| 226 |
liveuser |
5979 |
|
| 3 |
liveuser |
5980 |
#如果沒有輸出
|
|
|
5981 |
if(count($output)<1){
|
| 226 |
liveuser |
5982 |
|
| 3 |
liveuser |
5983 |
#設置執行失敗
|
|
|
5984 |
$result["status"]="false";
|
| 226 |
liveuser |
5985 |
|
| 3 |
liveuser |
5986 |
#設置錯誤訊息陣列
|
|
|
5987 |
$result["error"][]="no output from command(".$cmd.")";
|
| 226 |
liveuser |
5988 |
|
| 3 |
liveuser |
5989 |
#回傳結果
|
|
|
5990 |
return $result;
|
| 226 |
liveuser |
5991 |
|
| 3 |
liveuser |
5992 |
}#if end
|
| 226 |
liveuser |
5993 |
|
| 3 |
liveuser |
5994 |
#如果輸出不是 json
|
|
|
5995 |
if(json_validate($output[0])===false){
|
| 226 |
liveuser |
5996 |
|
| 3 |
liveuser |
5997 |
#設置執行失敗
|
|
|
5998 |
$result["status"]="false";
|
| 226 |
liveuser |
5999 |
|
| 3 |
liveuser |
6000 |
#設置錯誤訊息陣列
|
|
|
6001 |
$result["error"][]="output from command(".$cmd.") is not json";
|
| 226 |
liveuser |
6002 |
|
| 3 |
liveuser |
6003 |
#回傳結果
|
|
|
6004 |
return $result;
|
| 226 |
liveuser |
6005 |
|
| 3 |
liveuser |
6006 |
}#if end
|
| 226 |
liveuser |
6007 |
|
| 3 |
liveuser |
6008 |
#array of json decode
|
|
|
6009 |
$resArray=(array)(json_decode($output[0]));
|
| 226 |
liveuser |
6010 |
|
| 3 |
liveuser |
6011 |
#如果解析出來的元素數量不為2
|
|
|
6012 |
if(count($resArray)!==2){
|
| 226 |
liveuser |
6013 |
|
| 3 |
liveuser |
6014 |
#設置執行失敗
|
|
|
6015 |
$result["status"]="false";
|
| 226 |
liveuser |
6016 |
|
| 3 |
liveuser |
6017 |
#設置錯誤訊息陣列
|
|
|
6018 |
$result["error"][]="output from command(".$cmd.") is not valid";
|
| 226 |
liveuser |
6019 |
|
| 3 |
liveuser |
6020 |
#回傳結果
|
|
|
6021 |
return $result;
|
| 226 |
liveuser |
6022 |
|
| 3 |
liveuser |
6023 |
}#if end
|
| 226 |
liveuser |
6024 |
|
| 3 |
liveuser |
6025 |
#設置url encode後的內容
|
|
|
6026 |
$result["urlEncodeStr"]=urlencode($resArray[1]);
|
| 226 |
liveuser |
6027 |
|
| 3 |
liveuser |
6028 |
}#if end
|
| 226 |
liveuser |
6029 |
|
| 3 |
liveuser |
6030 |
#反之
|
|
|
6031 |
else{
|
| 226 |
liveuser |
6032 |
|
| 3 |
liveuser |
6033 |
#設置不需要 escape
|
|
|
6034 |
$result["required"]="false";
|
| 226 |
liveuser |
6035 |
|
| 3 |
liveuser |
6036 |
#設置 content 為未 escape 的內容
|
|
|
6037 |
$result["content"]=$altStr;
|
| 226 |
liveuser |
6038 |
|
| 3 |
liveuser |
6039 |
#設置url encode後的內容
|
|
|
6040 |
$result["urlEncodeStr"]=urlencode($result["content"]);
|
| 226 |
liveuser |
6041 |
|
| 3 |
liveuser |
6042 |
}#else end
|
| 226 |
liveuser |
6043 |
|
| 3 |
liveuser |
6044 |
}#if end
|
| 226 |
liveuser |
6045 |
|
| 3 |
liveuser |
6046 |
#反之
|
|
|
6047 |
else{
|
| 226 |
liveuser |
6048 |
|
| 3 |
liveuser |
6049 |
#設置不需要 escape
|
|
|
6050 |
$result["required"]="false";
|
| 226 |
liveuser |
6051 |
|
| 3 |
liveuser |
6052 |
#設置 content 為 str 的內容
|
|
|
6053 |
$result["content"]=$conf["str"];
|
| 226 |
liveuser |
6054 |
|
| 3 |
liveuser |
6055 |
#設置url encode後的內容
|
|
|
6056 |
$result["urlEncodeStr"]=urlencode($result["content"]);
|
| 226 |
liveuser |
6057 |
|
| 3 |
liveuser |
6058 |
}#else end
|
| 226 |
liveuser |
6059 |
|
| 3 |
liveuser |
6060 |
}#else end
|
| 226 |
liveuser |
6061 |
|
| 3 |
liveuser |
6062 |
}#if end
|
| 226 |
liveuser |
6063 |
|
|
|
6064 |
#反之
|
| 3 |
liveuser |
6065 |
else{
|
| 226 |
liveuser |
6066 |
|
| 3 |
liveuser |
6067 |
#設置需要 escape
|
|
|
6068 |
$result["required"]="true";
|
| 226 |
liveuser |
6069 |
|
| 3 |
liveuser |
6070 |
#設置 content 為原始內容
|
|
|
6071 |
$result["content"]=escapeshellarg("");
|
| 226 |
liveuser |
6072 |
|
| 3 |
liveuser |
6073 |
}#else end
|
|
|
6074 |
|
|
|
6075 |
#設置執行正常
|
|
|
6076 |
$result["status"]="true";
|
|
|
6077 |
|
|
|
6078 |
#回傳結果
|
|
|
6079 |
return $result;
|
|
|
6080 |
|
|
|
6081 |
}#function toSingleShellArg end
|
| 226 |
liveuser |
6082 |
|
| 3 |
liveuser |
6083 |
}#class stringProcess end
|
|
|
6084 |
|
|
|
6085 |
?>
|