Rev 548 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/php<?php#使用命名空間qbpwcfnamespace qbpwcf;#匯入外部套件require_once("qbpwcf/allInOne.php");#設定要讀取的檔案$file="./assets of stringProcess/https_error_504.log.txt";#函式說明:#依據行號分隔抓取檔案的內容,結果會回傳一個陣列#回傳的變數說明:#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.#$result["error"],錯誤訊息提示.#$result["warning"],警告訊息.#$result["function"],當前執行的函數名稱.#$result["fileContent"],爲檔案的內容陣列.#$result["lineCount"],爲檔案內容總共的行數.#$result["fullContent"],為檔案的完整內容.#$result["base64data"],為檔案的base64內容.#$result["mimeType"],為檔案的mime type.#必填參數:#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.$conf["filePositionAndName"]=$file;#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".$conf["web"]="false";#參考資料:#file(),取得檔案內容的行數.#file=>http:#php.net/manual/en/function.file.php#rtrim(),剔除透過file()取得每行內容結尾的換行符號.#filesize=>http://php.net/manual/en/function.filesize.php#參考資料:#無.#備註:#無.$getFileContent=fileAccess::getFileContent($conf);unset($conf);#如果執行失敗if($getFileContent["status"]==="false"){#印出錯誤var_dump($getFileContent);#錯誤離開exit(1);}#if end#初始化結果$result["content"]=array();#針對每個行內容foreach($getFileContent["fileContent"] as $lineNo => $lineContent){#將字串進行解析,取得兩個關鍵字中間的內容.#回傳結果:#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.#$result["function"],當前執行的函式內容.#$result["error"],錯誤訊息陣列.#$result["content"],取得的內容.#$result["oriStr"],原始的內容.#$result["found"],是否有找到符合條件的內容.#必填參數:#$conf["input"],字串,要處理的字串.$conf["input"]=$lineContent;#$conf["startKeyWord"],字串,開頭的關鍵字.$conf["startKeyWord"]="[";#$conf["endKeyWord"],字串,結束的關鍵字.$conf["endKeyWord"]="]";#可省略參數:#無.#參考資料:#無.#備註:#無.$getContentBetweenKeyWord=stringProcess::getContentBetweenKeyWord($conf);unset($conf);#如果執行失敗if($getContentBetweenKeyWord["status"]==="false"){#印出錯誤var_dump($getContentBetweenKeyWord);#錯誤離開exit(1);}#if end#var_dump($getContentBetweenKeyWord);exit;#如果無符合的內容if($getContentBetweenKeyWord["found"]==="false"){#下一行continue;}#if end#取得日期與時間$dateTime=$getContentBetweenKeyWord["content"];#var_dump($getContentBetweenKeyWord);#依照日期與時間記錄 對應的內容$result["content"][$dateTime][]=$lineContent;}#foreach end#針對每個 時間點foreach($result["content"] as $dateTime => $lines){#取得同時間的資料有多少筆$count=count($lines);#如果沒有同時間的資料if($count<2){#下一輪continue;}#if end#印出時間echo "Date Time:".$dateTime." ".$count." requests in same time".PHP_EOL;#針對每行內容foreach($lines as $line){#印出記錄echo $line.PHP_EOL;}#foreach end#結束這個時間的記錄echo PHP_EOL;}#foreach end?>