| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
#指定命名空間
|
|
|
4 |
namespace qbpwcf;
|
|
|
5 |
|
|
|
6 |
#匯入外部套件
|
|
|
7 |
include("../allInOne.php");
|
|
|
8 |
|
| 17 |
liveuser |
9 |
/*
|
|
|
10 |
|
| 1 |
liveuser |
11 |
#提示正在測試的方法
|
| 17 |
liveuser |
12 |
echo"<hr>search::getEqualVar - testCase 1<p>";
|
| 1 |
liveuser |
13 |
|
|
|
14 |
#涵式說明:
|
|
|
15 |
#檢查一個數值是否與陣列裏面的元素相同,如果有相同的則會傳其變數內容。
|
|
|
16 |
#回傳的結果:
|
|
|
17 |
#$result["status"],0表示有找到相同的,1表示沒有找到相同的。
|
|
|
18 |
#$result["equalVarName"],相等的變數內容。
|
|
|
19 |
#$result["equalVarPosition"],相同的元素內容其位置爲該陣列的key值。
|
|
|
20 |
#必填的參數:
|
|
|
21 |
$conf["conditionElement"]="light";#條件元素,要等於的元素內容。
|
|
|
22 |
$conf["compareElements"]=array("apple","desktop","light","smell");#要比對的陣列變數內容。
|
|
|
23 |
$result=search::getEqualVar($conf);
|
|
|
24 |
unset($conf);
|
|
|
25 |
|
|
|
26 |
#檢視回傳的結果
|
|
|
27 |
var_dump($result);
|
|
|
28 |
|
|
|
29 |
*/
|
|
|
30 |
|
| 17 |
liveuser |
31 |
/*
|
|
|
32 |
|
| 1 |
liveuser |
33 |
#提示正在測試的方法
|
|
|
34 |
echo"<hr>search::checkEquality - testCase 1<p>";
|
|
|
35 |
|
|
|
36 |
#涵式說明:
|
|
|
37 |
#檢查多個數值,是否與陣列裏面的某些元素相同。
|
|
|
38 |
#回傳的結果:
|
|
|
39 |
#$result["status"][$i],若爲0代表沒有相同的元素;反之0代表有相同的元素。
|
|
|
40 |
#$i爲第i+1個參數判斷後的結果。
|
|
|
41 |
#必填的參數:
|
|
|
42 |
$conf["inputElement"]=array(0,7,13);#想要找到的變數/數值。
|
|
|
43 |
$conf["blackBoxElement"]=array(0,1,2,3,4,5,6,7,8,9,10,11,12);#要從哪些變數/數值去尋找。
|
|
|
44 |
$result=search::checkEquality($conf);
|
|
|
45 |
unset($conf);
|
|
|
46 |
|
|
|
47 |
#檢視回傳的結果
|
|
|
48 |
var_dump($result);
|
|
|
49 |
|
|
|
50 |
*/
|
|
|
51 |
|
| 17 |
liveuser |
52 |
|
|
|
53 |
/*
|
|
|
54 |
|
| 1 |
liveuser |
55 |
#提示正在測試的方法
|
|
|
56 |
echo"<hr>search::getMeetConditionsString - testCase 1<p>";
|
|
|
57 |
|
|
|
58 |
#涵式說明:
|
|
|
59 |
#取得字首一樣的字串,並回傳其字串。
|
|
|
60 |
#回傳的結果:
|
|
|
61 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
62 |
#$result["status"],若爲0則代表有找到符合字首條件的結果;若爲1則代表失敗。
|
|
|
63 |
#必填的參數:
|
|
|
64 |
$conf["checkString"]="Linux fedora is a good OS.";#要檢查的字串
|
|
|
65 |
#可省略參數:
|
|
|
66 |
#$conf["frontWord"]=;#用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
67 |
$conf["frontWord"]="Lin";
|
|
|
68 |
#$conf["tailWord"]=;#用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
69 |
$conf["tailWord"]="OS.";
|
|
|
70 |
#參考資料:
|
|
|
71 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
72 |
var_dump(search::getMeetConditionsString($conf));
|
|
|
73 |
unset($conf);
|
|
|
74 |
|
|
|
75 |
*/
|
|
|
76 |
|
| 17 |
liveuser |
77 |
/*
|
|
|
78 |
|
| 1 |
liveuser |
79 |
#提示正在測試的方法
|
|
|
80 |
echo"<hr>search::getMeetConditionsString - testCase 2<p>";
|
|
|
81 |
|
|
|
82 |
#涵式說明:
|
|
|
83 |
#取得字首一樣的字串,並回傳其字串。
|
|
|
84 |
#回傳的結果:
|
|
|
85 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
86 |
#$result["status"],若爲0則代表有找到符合字首條件的結果;若爲1則代表失敗。
|
|
|
87 |
#必填的參數:
|
|
|
88 |
$conf["checkString"]="Linux fedora is a good OS.";#要檢查的字串
|
|
|
89 |
#可省略參數:
|
|
|
90 |
#$conf["frontWord"]=;#用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
91 |
$conf["frontWord"]="Lin";
|
|
|
92 |
#$conf["tailWord"]=;#用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
93 |
#$conf["tailWord"]="OS";
|
|
|
94 |
#參考資料:
|
|
|
95 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
96 |
var_dump(search::getMeetConditionsString($conf));
|
|
|
97 |
unset($conf);
|
|
|
98 |
|
|
|
99 |
*/
|
|
|
100 |
|
| 17 |
liveuser |
101 |
/*
|
|
|
102 |
|
| 1 |
liveuser |
103 |
#提示正在測試的方法
|
|
|
104 |
echo"<hr>search::getMeetConditionsString - testCase 3<p>";
|
|
|
105 |
|
|
|
106 |
#涵式說明:
|
|
|
107 |
#取得字首一樣的字串,並回傳其字串。
|
|
|
108 |
#回傳的結果:
|
|
|
109 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
110 |
#$result["status"],若爲0則代表有找到符合字首條件的結果;若爲1則代表失敗。
|
|
|
111 |
#必填的參數:
|
|
|
112 |
$conf["checkString"]="Linux fedora is a good OS.";#要檢查的字串
|
|
|
113 |
#可省略參數:
|
|
|
114 |
#$conf["frontWord"]=;#用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
115 |
#$conf["frontWord"]="Lin";
|
|
|
116 |
#$conf["tailWord"]=;#用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
117 |
$conf["tailWord"]="OS.";
|
|
|
118 |
#參考資料:
|
|
|
119 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
120 |
var_dump(search::getMeetConditionsString($conf));
|
|
|
121 |
unset($conf);
|
|
|
122 |
|
|
|
123 |
*/
|
|
|
124 |
|
|
|
125 |
/*
|
|
|
126 |
|
|
|
127 |
#提示正在測試的方法
|
|
|
128 |
echo"<hr>search::getMeetConditionsString - testCase 4<p>";
|
|
|
129 |
|
|
|
130 |
#涵式說明:
|
|
|
131 |
#取得字首一樣的字串,並回傳其字串。
|
|
|
132 |
#回傳的結果:
|
|
|
133 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
134 |
#$result["status"],若爲0則代表有找到符合字首條件的結果;若爲1則代表失敗。
|
|
|
135 |
#必填的參數:
|
|
|
136 |
$conf["checkString"]=" PRIMARY KEY (`id`)";#要檢查的字串
|
|
|
137 |
#可省略參數:
|
|
|
138 |
#$conf["frontWord"]=;#用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
139 |
#$conf["frontWord"]="Lin";
|
|
|
140 |
#$conf["tailWord"]=;#用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
141 |
$conf["tailWord"]=" `";
|
|
|
142 |
#參考資料:
|
|
|
143 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
144 |
var_dump(search::getMeetConditionsString($conf));
|
|
|
145 |
unset($conf);
|
|
|
146 |
|
|
|
147 |
*/
|
|
|
148 |
|
| 17 |
liveuser |
149 |
/*
|
|
|
150 |
|
| 1 |
liveuser |
151 |
#提示正在測試的方法
|
|
|
152 |
echo"<hr>search::getMeetConditionsStringMulti - testCase 1<p>";
|
|
|
153 |
|
|
|
154 |
#涵式說明:
|
|
|
155 |
#取得多個符合特定字首與字尾的字串.
|
|
|
156 |
#回傳的結果:
|
|
|
157 |
#$result["returnString"],爲符合字首條件的字串陣列內容。
|
|
|
158 |
#$result["status"],若爲"true"則代表第有找到符合字首條件的結果;若爲"false"則代表失敗。
|
|
|
159 |
#$result["error"],錯誤訊息陣列
|
|
|
160 |
#必填的參數:
|
|
|
161 |
#$conf["checkString"],陣列字串,要檢查的字串們
|
|
|
162 |
$conf["search::getMeetConditionsStringMulti"]["checkString"]=array("a-1","a-2","a-3","b-4","c3","a-9");#要檢查的字串陣列
|
|
|
163 |
#可省略參數:
|
|
|
164 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
165 |
$conf["search::getMeetConditionsStringMulti"]["frontWord"]="a-";
|
|
|
166 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
167 |
#$conf["search::getMeetConditionsStringMulti"]["tailWord"]="";
|
|
|
168 |
#參考資料:
|
|
|
169 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
170 |
var_dump(search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]));
|
|
|
171 |
unset($conf["search::getMeetConditionsStringMulti"]);
|
|
|
172 |
|
|
|
173 |
*/
|
|
|
174 |
|
| 17 |
liveuser |
175 |
/*
|
|
|
176 |
|
| 1 |
liveuser |
177 |
#提示正在測試的方法
|
|
|
178 |
echo"<hr>search::getMeetConditionsStringMulti - testCase 2<p>";
|
|
|
179 |
|
|
|
180 |
#涵式說明:
|
|
|
181 |
#取得多個符合特定字首與字尾的字串.
|
|
|
182 |
#回傳的結果:
|
|
|
183 |
#$result["returnString"],爲符合字首條件的字串陣列內容。
|
|
|
184 |
#$result["status"],若爲"true"則代表第有找到符合字首條件的結果;若爲"false"則代表失敗。
|
|
|
185 |
#$result["error"],錯誤訊息陣列
|
|
|
186 |
#必填的參數:
|
|
|
187 |
#$conf["checkString"],陣列字串,要檢查的字串們
|
|
|
188 |
$conf["search::getMeetConditionsStringMulti"]["checkString"]=array("a-1","a-2","a-3","b-4","c3","a-9");#要檢查的字串陣列
|
|
|
189 |
#可省略參數:
|
|
|
190 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
191 |
$conf["search::getMeetConditionsStringMulti"]["frontWord"]="a-";
|
|
|
192 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
193 |
$conf["search::getMeetConditionsStringMulti"]["tailWord"]="3";
|
|
|
194 |
#參考資料:
|
|
|
195 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
196 |
var_dump(search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]));
|
|
|
197 |
unset($conf["search::getMeetConditionsStringMulti"]);
|
|
|
198 |
|
|
|
199 |
*/
|
|
|
200 |
|
| 17 |
liveuser |
201 |
/*
|
|
|
202 |
|
| 1 |
liveuser |
203 |
#提示正在測試的方法
|
|
|
204 |
echo"<hr>search::getMeetConditionsStringMulti - testCase 3<p>";
|
|
|
205 |
|
|
|
206 |
#涵式說明:
|
|
|
207 |
#取得多個符合特定字首與字尾的字串.
|
|
|
208 |
#回傳的結果:
|
|
|
209 |
#$result["returnString"],爲符合字首條件的字串陣列內容。
|
|
|
210 |
#$result["status"],若爲"true"則代表第有找到符合字首條件的結果;若爲"false"則代表失敗。
|
|
|
211 |
#$result["error"],錯誤訊息陣列
|
|
|
212 |
#必填的參數:
|
|
|
213 |
#$conf["checkString"],陣列字串,要檢查的字串們
|
|
|
214 |
$conf["search::getMeetConditionsStringMulti"]["checkString"]=array("a-1","a-2","a-3","b-4","c3","a-9");#要檢查的字串陣列
|
|
|
215 |
#可省略參數:
|
|
|
216 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
217 |
#$conf["search::getMeetConditionsStringMulti"]["frontWord"]="a-";
|
|
|
218 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
219 |
$conf["search::getMeetConditionsStringMulti"]["tailWord"]="3";
|
|
|
220 |
#參考資料:
|
|
|
221 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
222 |
var_dump(search::getMeetConditionsStringMulti($conf["search::getMeetConditionsStringMulti"]));
|
|
|
223 |
unset($conf["search::getMeetConditionsStringMulti"]);
|
|
|
224 |
|
|
|
225 |
*/
|
|
|
226 |
|
| 17 |
liveuser |
227 |
/*
|
|
|
228 |
|
| 1 |
liveuser |
229 |
#提示正在測試的方法
|
|
|
230 |
echo"<hr>search::findKeyWord<p>";
|
|
|
231 |
|
|
|
232 |
#函式說明:
|
|
|
233 |
#檢查字串裡面有無指定的關鍵字
|
|
|
234 |
#回傳的結果:
|
|
|
235 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
236 |
#$result["error"],錯誤訊息
|
|
|
237 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
238 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
239 |
#必填的參數:
|
|
|
240 |
$conf["keyWord"]="../";#想要搜尋的關鍵字
|
|
|
241 |
$conf["string"]="../../../mobile/help.php";#要被搜尋的字串內容
|
|
|
242 |
#可省略的參數:
|
|
|
243 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
244 |
$result["search"]["findKeyWord"]=search::findKeyWord($conf);
|
|
|
245 |
unset($conf);
|
|
|
246 |
|
|
|
247 |
#檢查變數內容
|
|
|
248 |
var_dump($result["search"]["findKeyWord"]);
|
|
|
249 |
|
|
|
250 |
*/
|
|
|
251 |
|
| 17 |
liveuser |
252 |
/*
|
|
|
253 |
|
| 1 |
liveuser |
254 |
#提示正在測試的方法
|
|
|
255 |
echo"<hr>search::findManyKeyWordsFromManyString<p>";
|
|
|
256 |
|
|
|
257 |
#函式說明:
|
|
|
258 |
#檢查一個字串裡面是否有多個關鍵字
|
|
|
259 |
#回傳的結果:
|
|
|
260 |
#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
261 |
#$result[$i]["status"],第$i個字串搜尋是否成功,"true"代表執行成功,"false"代表執行失敗。
|
|
|
262 |
#$result[$i]["error"],第$i個字串搜尋的錯誤訊息陣列
|
|
|
263 |
#$result[$i]["founded"],第$i個字串搜尋,是否找到所有的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
264 |
#$result["foundedTrueKey"],["founded"]結果為"true"的元素key陣列。
|
|
|
265 |
#$result["foundedFalseKey"],["founded"]結果為"false"的元素key陣列。
|
|
|
266 |
#必填的參數:
|
|
|
267 |
$conf["keyWords"]=array("windows","linux","macOS");#想要搜尋的關鍵字
|
|
|
268 |
$conf["stringArray"][]="windows、linux、macOS,三者都是作業系統";
|
|
|
269 |
$conf["stringArray"][]="windows的圖形化界面是最有善的";
|
|
|
270 |
$conf["stringArray"][]="linux是openSource的,是我的最愛";
|
|
|
271 |
$conf["stringArray"][]="macOS是最昂貴,但是大家普遍使用後都覺得很棒的產品";
|
|
|
272 |
$conf["stringArray"][]="有些人認為人們應該要遠離資訊產品,回到大自然,這樣大家才會活的健康";
|
|
|
273 |
#$conf["stringArray"]=array("");#要被搜尋的字串內容陣列
|
|
|
274 |
#可省略的參數:
|
|
|
275 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
276 |
$result=search::findManyKeyWordsFromManyString($conf);
|
|
|
277 |
unset($conf);
|
|
|
278 |
|
|
|
279 |
#檢視回傳的結果
|
|
|
280 |
var_dump($result);
|
|
|
281 |
|
|
|
282 |
*/
|
|
|
283 |
|
| 17 |
liveuser |
284 |
/*
|
|
|
285 |
|
| 1 |
liveuser |
286 |
#提示正在測試的方法
|
|
|
287 |
echo"<hr>search::filterString<p>";
|
|
|
288 |
|
|
|
289 |
#函式說明:
|
|
|
290 |
#檢查一個字串裡面是否沒有多個任何關鍵字存在
|
|
|
291 |
#回傳的結果:
|
|
|
292 |
#$result["status"],執行是否成功的識別,"true"為執行成功;"false"為執行失敗
|
|
|
293 |
#$result["error"],錯誤訊息陣列
|
|
|
294 |
#$result["filtered"],該字串是否為要過濾掉的,"true"為要過濾掉的;"false"為不用過濾掉的
|
|
|
295 |
#必填的參數:
|
|
|
296 |
$conf["inputStr"]="Hello!";#要過濾的字串
|
|
|
297 |
$conf["filterWord"]=array("#","=","}");#要過濾的字串不能含有該陣列元素之一
|
|
|
298 |
$result["search"]["filterString"]=search::filterString($conf);
|
|
|
299 |
unset($conf);
|
|
|
300 |
|
|
|
301 |
var_dump($result["search"]["filterString"]);
|
|
|
302 |
|
|
|
303 |
*/
|
|
|
304 |
|
| 17 |
liveuser |
305 |
/*
|
|
|
306 |
|
| 1 |
liveuser |
307 |
#提示正在測試的方法
|
|
|
308 |
echo"<hr>search::filterMutiString<p>";
|
|
|
309 |
|
|
|
310 |
#函式說明:
|
|
|
311 |
#檢查多個字串裡面是否沒有多個任何篩選字存在
|
|
|
312 |
#回傳的結果:
|
|
|
313 |
#$result["status"],執行是否成功的識別,"true"為執行成功;"false"為執行失敗
|
|
|
314 |
#$result["error"],錯誤訊息陣列
|
|
|
315 |
#$result["filtered"],該字串是否為要過濾掉的識別陣列,"true"為要過濾掉的;"false"為不用過濾掉的
|
|
|
316 |
#必填的參數:
|
|
|
317 |
$conf["inputStr"]=array("Hello!","$%$%$&@#$%^","a={1,2,4}");#要過濾的字串陣列
|
|
|
318 |
$conf["filterWord"]=array("#","=","}");#要過濾的字串不能含有該陣列元素之一
|
|
|
319 |
$result["search"]["filterMutiString"]=search::filterMutiString($conf);
|
|
|
320 |
unset($conf);
|
|
|
321 |
|
|
|
322 |
var_dump($result["search"]["filterMutiString"]);
|
|
|
323 |
|
|
|
324 |
*/
|
|
|
325 |
|
| 17 |
liveuser |
326 |
/*
|
|
|
327 |
|
| 1 |
liveuser |
328 |
#提示正在測試的方法
|
|
|
329 |
echo"<hr>search::findKeyWordPosition - testCase 1<p>";
|
|
|
330 |
|
|
|
331 |
#涵式說明:
|
|
|
332 |
#取得關鍵字在字串的哪個位置
|
|
|
333 |
#回傳結果:
|
|
|
334 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
335 |
#$result["error"],錯誤訊息陣列.
|
|
|
336 |
#$result["function"],當前執行的函數名稱.
|
|
|
337 |
#$result["argu"],傳入的參數.
|
|
|
338 |
#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
|
|
|
339 |
#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
|
|
|
340 |
#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
|
|
|
341 |
#必填參數:
|
|
|
342 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
343 |
$conf["inputStr"]="(\$i)";
|
|
|
344 |
#$conf["keyWord"],字串,關鍵字.
|
|
|
345 |
$conf["keyWord"]="\$i";
|
|
|
346 |
#參考資料:
|
|
|
347 |
#http://php.net/manual/en/function.strpos.php
|
|
|
348 |
var_dump(search::findKeyWordPosition($conf));
|
|
|
349 |
unset($conf);
|
|
|
350 |
|
|
|
351 |
*/
|
|
|
352 |
|
| 17 |
liveuser |
353 |
/*
|
|
|
354 |
|
| 1 |
liveuser |
355 |
#提示正在測試的方法
|
|
|
356 |
echo"<hr>search::findKeyWordPosition - testCase 2<p>";
|
|
|
357 |
|
|
|
358 |
#涵式說明:
|
|
|
359 |
#取得關鍵字在字串的哪個位置
|
|
|
360 |
#回傳結果:
|
|
|
361 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
362 |
#$result["error"],錯誤訊息陣列.
|
|
|
363 |
#$result["function"],當前執行的函數名稱.
|
|
|
364 |
#$result["argu"],傳入的參數.
|
|
|
365 |
#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
|
|
|
366 |
#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
|
|
|
367 |
#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
|
|
|
368 |
#必填參數:
|
|
|
369 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
370 |
$conf["inputStr"]="\$i)";
|
|
|
371 |
#$conf["keyWord"],字串,關鍵字.
|
|
|
372 |
$conf["keyWord"]="\$i";
|
|
|
373 |
#參考資料:
|
|
|
374 |
#http://php.net/manual/en/function.strpos.php
|
|
|
375 |
var_dump(search::findKeyWordPosition($conf));
|
|
|
376 |
unset($conf);
|
|
|
377 |
|
|
|
378 |
*/
|
|
|
379 |
|
| 17 |
liveuser |
380 |
/*
|
|
|
381 |
|
| 1 |
liveuser |
382 |
#提示正在測試的方法
|
|
|
383 |
echo"<hr>search::findKeyWordPosition - testCase 3<p>";
|
|
|
384 |
|
|
|
385 |
#涵式說明:
|
|
|
386 |
#取得關鍵字在字串的哪個位置
|
|
|
387 |
#回傳結果:
|
|
|
388 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
389 |
#$result["error"],錯誤訊息陣列.
|
|
|
390 |
#$result["function"],當前執行的函數名稱.
|
|
|
391 |
#$result["argu"],傳入的參數.
|
|
|
392 |
#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
|
|
|
393 |
#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
|
|
|
394 |
#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
|
|
|
395 |
#必填參數:
|
|
|
396 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
397 |
$conf["inputStr"]="(\$i";
|
|
|
398 |
#$conf["keyWord"],字串,關鍵字.
|
|
|
399 |
$conf["keyWord"]="\$i";
|
|
|
400 |
#參考資料:
|
|
|
401 |
#http://php.net/manual/en/function.strpos.php
|
|
|
402 |
var_dump(search::findKeyWordPosition($conf));
|
|
|
403 |
unset($conf);
|
|
|
404 |
|
|
|
405 |
*/
|
|
|
406 |
|
| 17 |
liveuser |
407 |
/*
|
|
|
408 |
|
| 1 |
liveuser |
409 |
#提示正在測試的方法
|
|
|
410 |
echo"<hr>search::findKeyWordPosition - testCase 4<p>";
|
|
|
411 |
|
|
|
412 |
#涵式說明:
|
|
|
413 |
#取得關鍵字在字串的哪個位置
|
|
|
414 |
#回傳結果:
|
|
|
415 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
416 |
#$result["error"],錯誤訊息陣列.
|
|
|
417 |
#$result["function"],當前執行的函數名稱.
|
|
|
418 |
#$result["argu"],傳入的參數.
|
|
|
419 |
#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
|
|
|
420 |
#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
|
|
|
421 |
#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
|
|
|
422 |
#必填參數:
|
|
|
423 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
424 |
$conf["inputStr"]="\$i";
|
|
|
425 |
#$conf["keyWord"],字串,關鍵字.
|
|
|
426 |
$conf["keyWord"]="\$i";
|
|
|
427 |
#參考資料:
|
|
|
428 |
#http://php.net/manual/en/function.strpos.php
|
|
|
429 |
var_dump(search::findKeyWordPosition($conf));
|
|
|
430 |
unset($conf);
|
|
|
431 |
|
|
|
432 |
*/
|
|
|
433 |
|
| 17 |
liveuser |
434 |
/*
|
|
|
435 |
|
| 1 |
liveuser |
436 |
#提示正在測試的方法
|
|
|
437 |
echo"<hr>search::findKeyWordPosition - testCase 5<p>";
|
|
|
438 |
|
|
|
439 |
#涵式說明:
|
|
|
440 |
#取得關鍵字在字串的哪個位置
|
|
|
441 |
#回傳結果:
|
|
|
442 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
443 |
#$result["error"],錯誤訊息陣列.
|
|
|
444 |
#$result["function"],當前執行的函數名稱.
|
|
|
445 |
#$result["argu"],傳入的參數.
|
|
|
446 |
#$result["head"],關鍵字是否在字串的開頭,"true"代表是,"false"代表不是.
|
|
|
447 |
#$result["tail"],關鍵字是否在字串的尾端,"true"代表是,"false"代表不是.
|
|
|
448 |
#$result["center"],關鍵字是否在字串的中間,"true"代表是,"false"代表不是.
|
|
|
449 |
#必填參數:
|
|
|
450 |
#$conf["inputStr"],字串,被搜尋的字串.
|
|
|
451 |
$conf["inputStr"]="(\$i)";
|
|
|
452 |
#$conf["keyWord"],字串,關鍵字.
|
|
|
453 |
$conf["keyWord"]="\$j";
|
|
|
454 |
#參考資料:
|
|
|
455 |
#http://php.net/manual/en/function.strpos.php
|
|
|
456 |
var_dump(search::findKeyWordPosition($conf));
|
|
|
457 |
unset($conf);
|
|
|
458 |
|
|
|
459 |
*/
|
|
|
460 |
|
| 17 |
liveuser |
461 |
/*
|
|
|
462 |
|
| 1 |
liveuser |
463 |
#提示正在測試的方法
|
|
|
464 |
echo"<hr>search::getContentBetweenKeyWord - testCase 1<p>";
|
|
|
465 |
|
|
|
466 |
#函式說明:
|
|
|
467 |
#取得兩關鍵字中的內容.
|
|
|
468 |
#必填參數:
|
|
|
469 |
#$conf["input"],字串,要解析的字串.
|
|
|
470 |
$conf["input"]="div[3]";
|
|
|
471 |
#$conf["leftKeyWord"],字串,左邊的關鍵字.
|
|
|
472 |
$conf["leftKeyWord"]="[";
|
|
|
473 |
#$conf["rightKeyWord"],字串,右邊的關鍵字.
|
|
|
474 |
$conf["rightKeyWord"]="]";
|
|
|
475 |
#參考資料
|
|
|
476 |
#sscanf=>http://php.net/manual/en/function.sscanf.php
|
|
|
477 |
$getContentBetweenKeyWord=search::getContentBetweenKeyWord($conf);
|
|
|
478 |
unset($conf);
|
|
|
479 |
|
|
|
480 |
#如果執行失敗
|
|
|
481 |
if($getContentBetweenKeyWord["status"]==="false"){
|
|
|
482 |
|
|
|
483 |
#印出內容
|
|
|
484 |
var_dump($getContentBetweenKeyWord);
|
|
|
485 |
|
|
|
486 |
#停止執行
|
|
|
487 |
exit;
|
|
|
488 |
|
|
|
489 |
}#if end
|
|
|
490 |
|
|
|
491 |
#反之
|
|
|
492 |
else{
|
|
|
493 |
|
|
|
494 |
#印出內容
|
|
|
495 |
var_dump($getContentBetweenKeyWord);
|
|
|
496 |
|
|
|
497 |
}#else end
|
|
|
498 |
|
|
|
499 |
*/
|
|
|
500 |
|
| 17 |
liveuser |
501 |
/*
|
|
|
502 |
|
| 1 |
liveuser |
503 |
#提示正在測試的方法
|
|
|
504 |
echo"<hr>search::findKeyWordInFile - testCase 1<p>";
|
|
|
505 |
|
|
|
506 |
#函式說明:
|
|
|
507 |
#尋找檔案裡面有無關鍵字存在,取得其所在列數與內容.
|
|
|
508 |
#回傳結果:
|
|
|
509 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
510 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
511 |
#$result["function"],當前執行的函式名稱.
|
|
|
512 |
#$result["argu"],所使用的參數.
|
|
|
513 |
#$result["content"],符合的列數與內容.
|
|
|
514 |
#$result["content"][$i]["LN"],第$i+1個符合條件的列數.
|
|
|
515 |
#$result["content"][$i]["LC"],第$i+1個符合條件的列內容.
|
|
|
516 |
#必填參數:
|
|
|
517 |
#$conf["fileAddr"],字串,檔案的路徑與名稱.
|
|
|
518 |
$conf["fileAddr"]="searchT.php";
|
|
|
519 |
#$conf["keyWord"],字串,要搜尋的關鍵字.
|
|
|
520 |
$conf["keyWord"]="keyWord";
|
|
|
521 |
#$conf["fileArgu"],字串,__FILE__的內容
|
|
|
522 |
$conf["fileArgu"]=__FILE__;
|
|
|
523 |
$findKeyWordInFile=search::findKeyWordInFile($conf);
|
|
|
524 |
unset($conf);
|
|
|
525 |
|
|
|
526 |
#如果尋找關鍵字失敗
|
|
|
527 |
if($findKeyWordInFile["status"]==="false"){
|
|
|
528 |
|
|
|
529 |
#印出內容
|
|
|
530 |
var_dump($findKeyWordInFile);
|
|
|
531 |
|
|
|
532 |
#結束程式
|
|
|
533 |
exit;
|
|
|
534 |
|
|
|
535 |
}#if end
|
|
|
536 |
|
|
|
537 |
#印出內容
|
|
|
538 |
var_dump($findKeyWordInFile);
|
|
|
539 |
|
|
|
540 |
*/
|
|
|
541 |
|
| 17 |
liveuser |
542 |
/*
|
|
|
543 |
|
| 1 |
liveuser |
544 |
#提示正在測試的方法
|
|
|
545 |
echo"<hr>search::findLikelyStr - testCase 1<p>";
|
|
|
546 |
|
|
|
547 |
#涵式說明:
|
|
|
548 |
#透過lsblk指令的輸出取得已經掛載的blk.
|
|
|
549 |
#回傳結果:
|
|
|
550 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
551 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
552 |
#$result["function"],當前執行的函式名稱.
|
|
|
553 |
#$result["content"],lsblk的輸出內容.
|
|
|
554 |
#必填參數:
|
|
|
555 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
556 |
$conf["fileArgu"]=__FILE__;
|
|
|
557 |
#可省略參數:
|
|
|
558 |
#無.
|
|
|
559 |
$lsblk=cmd::lsblk($conf);
|
|
|
560 |
unset($conf);
|
|
|
561 |
|
|
|
562 |
#如果執行失敗
|
|
|
563 |
if($lsblk["status"]==="false"){
|
|
|
564 |
|
|
|
565 |
#印出結果
|
|
|
566 |
var_dump($lsblk);
|
|
|
567 |
|
|
|
568 |
#結束執行
|
|
|
569 |
exit;
|
|
|
570 |
|
|
|
571 |
}#if end
|
|
|
572 |
|
|
|
573 |
#函式說明:
|
|
|
574 |
#尋找字串是否存在對應的關鍵字,且符合的最常關鍵字為何?
|
|
|
575 |
#回傳結果:
|
|
|
576 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
577 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
578 |
#$result["function"],當前執行的函式名稱.
|
|
|
579 |
#$result["argu"],所使用的參數.
|
|
|
580 |
#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
|
|
|
581 |
#$result["content"],最符合的字串完整內容.
|
|
|
582 |
#必填參數:
|
|
|
583 |
#$conf["input"],字串,要比對的字串陣列.
|
|
|
584 |
$conf["input"]=__FILE__;
|
|
|
585 |
#$conf["keyWord"],字串陣列,要搜尋的關鍵字.
|
|
|
586 |
$conf["keyWord"]=$lsblk["content"]["MOUNTPOINT"];
|
|
|
587 |
$findLikelyStr=search::findLikelyStr($conf);
|
|
|
588 |
unset($conf);
|
|
|
589 |
|
|
|
590 |
#如果執行失敗
|
|
|
591 |
if($findLikelyStr["status"]==="false"){
|
|
|
592 |
|
|
|
593 |
#印出結果
|
|
|
594 |
var_dump($findLikelyStr);
|
|
|
595 |
|
|
|
596 |
#結束執行
|
|
|
597 |
exit;
|
|
|
598 |
|
|
|
599 |
}#if end
|
|
|
600 |
|
|
|
601 |
#印出結果
|
|
|
602 |
var_dump($findLikelyStr);
|
|
|
603 |
|
|
|
604 |
*/
|
|
|
605 |
|
|
|
606 |
/*
|
|
|
607 |
|
|
|
608 |
#提示正在測試的方法
|
|
|
609 |
echo"<hr>search::findKeyInArray - testCase 1<p>";
|
|
|
610 |
|
|
|
611 |
#說明:
|
|
|
612 |
#尋找陣列中有無符合的key
|
|
|
613 |
#回傳結果:
|
|
|
614 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
615 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
616 |
#$result["function"],當前執行的函式名稱.
|
|
|
617 |
#$result["argu"],所使用的參數.
|
|
|
618 |
#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
|
|
|
619 |
#必填參數:
|
|
|
620 |
#$conf["key"],字串,要尋找的key.
|
|
|
621 |
$conf["key"]="target";
|
|
|
622 |
#$conf["array"],陣列,要被搜尋的陣列.
|
|
|
623 |
$conf["array"]=array("a"=>"sdad","b"=>"adadad","target"=>"dscsdcsd");
|
|
|
624 |
$findKeyInArray=search::findKeyInArray($conf);
|
|
|
625 |
unset($conf);
|
|
|
626 |
|
|
|
627 |
#如果執行失敗
|
|
|
628 |
if($findKeyInArray["status"]==="false"){
|
|
|
629 |
|
|
|
630 |
#印出結果
|
|
|
631 |
var_dump($findKeyInArray);
|
|
|
632 |
|
|
|
633 |
#結束執行
|
|
|
634 |
exit;
|
|
|
635 |
|
|
|
636 |
}#if end
|
|
|
637 |
|
|
|
638 |
var_dump($findKeyInArray);
|
|
|
639 |
|
|
|
640 |
*/
|
|
|
641 |
|
|
|
642 |
/*
|
|
|
643 |
|
|
|
644 |
#提示正在測試的方法
|
|
|
645 |
echo"<hr>search::findKeyInArray - testCase 2<p>";
|
|
|
646 |
|
|
|
647 |
#說明:
|
|
|
648 |
#尋找陣列中有無符合的key
|
|
|
649 |
#回傳結果:
|
|
|
650 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
651 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
652 |
#$result["function"],當前執行的函式名稱.
|
|
|
653 |
#$result["argu"],所使用的參數.
|
|
|
654 |
#$result["founded"],是否有找到關鍵字,"true"代表有找到,"false"代表沒有找到.
|
|
|
655 |
#必填參數:
|
|
|
656 |
#$conf["key"],字串,要尋找的key.
|
|
|
657 |
$conf["key"]="target";
|
|
|
658 |
#$conf["array"],陣列,要被搜尋的陣列.
|
|
|
659 |
$conf["array"]=array("a"=>"sdad","b"=>"adadad","c"=>"dscsdcsd");
|
|
|
660 |
$findKeyInArray=search::findKeyInArray($conf);
|
|
|
661 |
unset($conf);
|
|
|
662 |
|
|
|
663 |
#如果執行失敗
|
|
|
664 |
if($findKeyInArray["status"]==="false"){
|
|
|
665 |
|
|
|
666 |
#印出結果
|
|
|
667 |
var_dump($findKeyInArray);
|
|
|
668 |
|
|
|
669 |
#結束執行
|
|
|
670 |
exit;
|
|
|
671 |
|
|
|
672 |
}#if end
|
|
|
673 |
|
|
|
674 |
var_dump($findKeyInArray);
|
|
|
675 |
|
|
|
676 |
*/
|
|
|
677 |
|
|
|
678 |
?>
|