Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 548 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

/*

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2023 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.

*/
namespace qbpwcf;

/*
類別說明:
跟解析內容相關的類別
備註:
無.
*/
class parser{

        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #參考資料:
        #__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        */
        public function __call($method,$arguments){

                #取得當前執行的函式
                $result["function"]=__FUNCTION__;

                #設置執行不正常
                $result["status"]="false";

                #設置執行錯誤
                $result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";

                #設置所丟入的參數
                $result["error"][]=$arguments;

                #回傳結果
                return $result;

                }#function __call end

        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #參考資料:
        #__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        */
        public static function __callStatic($method,$arguments){

                #取得當前執行的函式
                $result["function"]=__FUNCTION__;

                #設置執行不正常
                $result["status"]="false";

                #設置執行錯誤
                $result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";

                #設置所丟入的參數
                $result["error"][]=$arguments;

                #回傳結果
                return $result;

                }#function __callStatic end
                
        /*
        #函式說明:
        #解析 ss 指令的輸出
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #$result["argu"],使用的參數.
        #$result["columns"],解析好的欄位名稱陣列.
        #$result["content"],解析好的內容陣列.
        #必填參數:
        #$conf["input"],字串陣列,要解析的內容,包含header.
        $conf["input"]=array();
        #可省略參數:
        #無.
        #參考資料:
        #無.
        #備註:
        #無.
        */
        public static function ss(&$conf){
        
                #初始化要回傳的結果
                $result=array();
                
                #取得當前執行的函數名稱
                $result["function"]=__FUNCTION__;
                
                #如果 $conf 不為陣列
                if(gettype($conf)!="array"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf變數須為陣列形態";

                        #如果傳入的參數為 null
                        if($conf==null){
                                
                                #設置執行錯誤訊息
                                $result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
                                
                                }#if end

                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #取得參數
                $result["argu"]=$conf;
                        
                #函式說明:
                #檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],執行不正常結束的錯訊息陣列.
                #$result["simpleError"],簡單表示的錯誤訊息.
                #$result["function"],當前執行的函式名稱.
                #$result["argu"],設置給予的參數.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
                #$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
                #$result["argu"],字串陣列,目前輸入的參數名稱陣列.
                #$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
                #$result["notNeedVar"],字串陣列,多餘的參數名稱.
                #必填參數:
                #$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck::checkArguments"]["varInput"]=&$conf;
                #$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可省略參數:
                #$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input");
                #$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
                #$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
                $conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
                #$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
                #$conf["canNotBeEmpty"]=array();
                #$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
                #$conf["canBeEmpty"]=array();
                #$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
                #$conf["skipableVariableCanNotBeEmpty"]=array();
                #$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                #$conf["skipableVariableName"]=array();
                #$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
                #$conf["skipableVariableType"]=array();
                #$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                #$conf["skipableVarDefaultValue"]=array("");
                #$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
                #$conf["disallowAllSkipableVarIsEmpty"]="";
                #$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
                #$conf["disallowAllSkipableVarIsEmptyArray"]="";
                #$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["arrayCountEqualCheck"][]=array();
                #參考資料:
                #array_keys=>http://php.net/manual/en/function.array-keys.php
                #備註:
                #無.
                $checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);
        
                #如果執行失敗
                if($checkArguments["status"]==="false"){
                
                        #設置執行失敗
                        $result["status"]="false";

                        #設置錯誤訊息
                        $result["error"]=$checkArguments;

                        #回傳結果
                        return $result;
                
                        }#if end
                        
                #如果參數檢查不通過
                if($checkArguments["passed"]==="false"){
                
                        #設置執行失敗
                        $result["status"]="false";

                        #設置錯誤訊息
                        $result["error"]=$checkArguments;

                        #回傳結果
                        return $result;
                
                        }#if end
                        
                #取得 header
                $headerStr=$conf["input"][0];
                
                #移除標題列
                unset($conf["input"][0]);
        
                #解析 header
                #Netid                     Recv-Q                      Send-Q                                                                             Local Address:Port                                             Peer Address:Port 
                #Netid State  Recv-Q Send-Q                                   Local Address:Port        Peer Address:PortProcess
                #函式說明:
                #將固定格式的字串分開,並回傳分開的結果.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息陣列
                #$result["function"],當前執行的函數名稱.
                #$result["argu"],使用的參數.
                #$result["oriStr"],要分割的原始字串內容
                #$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
                #$result["dataCounts"],爲總共分成幾段
                #$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
                #必填參數:
                #$conf["stringIn"],字串,要處理的字串.
                $conf["stringProcess::spiltString"]["stringIn"]=$headerStr;
                #$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
                $conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
                #可省略參數:
                #$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
                $conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
                #參考資料:
                #無.
                #備註:
                #無.
                $spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
                unset($conf["stringProcess::spiltString"]);
        
                #如果執行失敗
                if($spiltString["status"]==="false"){
                
                        #設置執行失敗
                        $result["status"]="false";

                        #設置錯誤訊息
                        $result["error"]=$spiltString;

                        #回傳結果
                        return $result;
                
                        }#if end
                        
                #如果執行失敗
                if($spiltString["dataCounts"]<=1){
                
                        #設置執行失敗
                        $result["status"]="false";

                        #設置錯誤訊息
                        $result["error"]=$spiltString;

                        #回傳結果
                        return $result;
                
                        }#if end
                        
                #針對可能的欄位名稱
                for($i=0;$i<count($spiltString["dataArray"]);$i++){
                
                        #取得該段內容
                        $column=$spiltString["dataArray"][$i];
                
                        #如果欄位開頭為空格
                        while(strpos($column," ")===0){
                        
                                #剔除開頭的空格
                                $column=substr($column,1);
                        
                                }#while end
                                
                        #如果有下一個欄位
                        if(isset($spiltString["dataArray"][$i+1])){
                        
                                #如果下一個不是完整的欄位名稱
                                if(strpos($spiltString["dataArray"][$i+1],":")!==false){
                                
                                        #更新欄位名稱
                                        $column=$column." ".$spiltString["dataArray"][$i+1];
                                
                                        #跳過下個欄位
                                        $i=$i+1;
                                
                                        }#if end
                        
                                }#if end
                        
                        #如果需要判斷
                        if(strlen($column)>=strlen("Process")){
                        
                                #函式說明:
                                #取得符合特定字首與字尾的字串
                                #回傳結果:
                                #$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
                                #$result["function"],當前執行的函數名稱.
                                #$result["error"],錯誤訊息陣列.
                                #$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
                                #$result["content"],符合條件的字串,去掉字首字尾後的結果.
                                #$result["returnString"],爲符合字首字、尾條件的字串內容。
                                #$result["argu"],使用的參數.
                                #必填參數:
                                #$conf["checkString"],字串,要檢查的字串.
                                $conf["search::getMeetConditionsString"]["checkString"]=$column;
                                #可省略參數:
                                #$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
                                #$conf["frontWord"]="";
                                #$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
                                $conf["search::getMeetConditionsString"]["tailWord"]="Process";
                                #參考資料:
                                #str_spilt(),可以將字串依照字母分割成一個個陣列字串。
                                #備註:
                                #無.
                                $getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
                                unset($conf["search::getMeetConditionsString"]);
                                
                                #如果執行失敗
                                if($getMeetConditionsString["status"]==="false"){
                                
                                        #設置執行失敗
                                        $result["status"]="false";

                                        #設置錯誤訊息
                                        $result["error"]=$getMeetConditionsString;

                                        #回傳結果
                                        return $result;
                                
                                        }#if end
                                
                                #如果欄位名稱結尾為 "Process"
                                if($getMeetConditionsString["founded"]==="true"){
                                
                                        #儲存欄位名稱
                                        $result["columns"][]=$getMeetConditionsString["content"];
                                
                                        #儲存欄位名稱
                                        $result["columns"][]="Process";
                                
                                        #換下一個
                                        continue;
                                
                                        }#if end
                        
                                }#if end
                                
                        #儲存欄位名稱
                        $result["columns"][]=$column;
                
                        }#foreach end
                        
                #break point
                #var_dump($conf["input"]);exit;
                        
                #針對每列內容:
                #可能為:
                #"nl    UNCONN 0      0                                                    0:47                      *"
                #"tcp   LISTEN 0      128                                        169.254.1.1:22               0.0.0.0:*    users:(("sshd",pid=2920,fd=3))"
                #“nl    UNCONN 0      0                                                   18:0                       *”
                foreach($conf["input"] as $line){
                
                        #函式說明:
                        #將固定格式的字串分開,並回傳分開的結果.
                        #回傳結果:
                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                        #$result["error"],錯誤訊息陣列
                        #$result["function"],當前執行的函數名稱.
                        #$result["argu"],使用的參數.
                        #$result["oriStr"],要分割的原始字串內容
                        #$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
                        #$result["dataCounts"],爲總共分成幾段
                        #$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
                        #必填參數:
                        #$conf["stringIn"],字串,要處理的字串.
                        $conf["stringProcess::spiltString"]["stringIn"]=$line;
                        #$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
                        $conf["stringProcess::spiltString"]["spiltSymbol"]="  ";
                        #可省略參數:
                        #$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
                        $conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
                        #參考資料:
                        #無.
                        #備註:
                        #無.
                        $spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
                        unset($conf["stringProcess::spiltString"]);
                
                        #如果執行失敗
                        if($spiltString["status"]==="false"){
                        
                                #設置執行失敗
                                $result["status"]="false";

                                #設置錯誤訊息
                                $result["error"]=$spiltString;

                                #回傳結果
                                return $result;
                        
                                }#if end
                                
                        #如果執行失敗
                        if($spiltString["dataCounts"]<=1){
                        
                                #設置執行失敗
                                $result["status"]="false";

                                #設置錯誤訊息
                                $result["error"]=$spiltString;

                                #回傳結果
                                return $result;
                        
                                }#if end
                                
                        #break ponint
                        #var_dump($spiltString);exit;   
                                
                        #取得欄位內容
                        foreach($spiltString["dataArray"] as $index=>$data){
                        
                                #如果資料開頭為空格
                                while(strpos($data," ")===0){
                                
                                        #剔除開頭的空格
                                        $data=substr($data,1);
                                        
                                        #更新資料
                                        $spiltString["dataArray"][$index]=$data;
                                
                                        }#while end
                                
                                #如果空格在中間
                                if(strpos($data," ")!==false){
                                
                                        #如果沒有 * 跟 /
                                        if( strpos($data,"*")===false && strpos($data,"/")===false ){
                                
                                                #代表要切割成多個資料欄位
                                                #函式說明:
                                                #將固定格式的字串分開,並回傳分開的結果.
                                                #回傳結果:
                                                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                                                #$result["error"],錯誤訊息陣列
                                                #$result["function"],當前執行的函數名稱.
                                                #$result["argu"],使用的參數.
                                                #$result["oriStr"],要分割的原始字串內容
                                                #$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
                                                #$result["dataCounts"],爲總共分成幾段
                                                #$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
                                                #必填參數:
                                                #$conf["stringIn"],字串,要處理的字串.
                                                $conf["stringProcess::spiltString"]["stringIn"]=$data;
                                                #$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
                                                $conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
                                                #可省略參數:
                                                #$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
                                                $conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
                                                #參考資料:
                                                #無.
                                                #備註:
                                                #無.
                                                $spiltStringFor2section=stringProcess::spiltString($conf["stringProcess::spiltString"]);
                                                unset($conf["stringProcess::spiltString"]);
                                
                                                #如果執行失敗
                                                if($spiltStringFor2section["status"]==="false"){
                                                
                                                        #設置執行失敗
                                                        $result["status"]="false";

                                                        #設置錯誤訊息
                                                        $result["error"]=$spiltStringFor2section;

                                                        #回傳結果
                                                        return $result;
                                                
                                                        }#if end
                                                        
                                                #如果沒有分割出東西來
                                                if($spiltStringFor2section["dataCounts"]===1){
                                                
                                                        #設置執行失敗
                                                        $result["status"]="false";

                                                        #設置錯誤訊息
                                                        $result["error"]=$spiltStringFor2section;

                                                        #回傳結果
                                                        return $result;
                                                
                                                        }#if end
                                
                                                #更新 data array
                                                $spiltString["dataArray"]=$spiltStringFor2section["dataArray"];
                                
                                                #更新 data count
                                                $spiltString["dataCount"]=count($spiltString["dataArray"]);
                                                
                                                #更新當前的 $data
                                                $data=$spiltString["dataArray"][$index];
                                
                                                }#if end
                                
                                        }#if end
                                
                                /*
                                #debug
                                if($index>=7){
                                
                                        var_dump($spiltString);
                                        exit;
                                
                                        }#if end
                                */
                        
                                #debug
                                #var_dump("原始內容:".$line);
                                #var_dump($result["columns"][$index]." => ".$data);
                        
                                #如果是 “Local Address:Port” 欄位的數值
                                if($result["columns"][$index]==="Local Address:Port"){
                                
                                        #get columns index of "Netid"
                                        #函式說明:
                                        #檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
                                        #回傳結果:
                                        #$result["status"],"true"表示執行正確,"false"表示執行錯誤.
                                        #$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
                                        #$result["error"],錯誤訊息
                                        #$result["function"],當前執行的函數名稱
                                        #$result["argv"],使用的參數
                                        #$result["equalVarName"],相等的變數名稱或key.
                                        #$result["equalVarValue"],相等的變數數值內容.
                                        #必填參數:
                                        #$conf["conditionElement"],字串,條件元素,要等於的元素內容.
                                        $conf["search::getEqualVar"]["conditionElement"]="Netid";
                                        #$conf["compareElements"],字串陣列,要比對的陣列變數內容.
                                        $conf["search::getEqualVar"]["compareElements"]=$result["columns"];
                                        #可省略參數:
                                        #無.
                                        #參考資料:
                                        #無.
                                        #備註:
                                        #無.
                                        $getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
                                        unset($conf["search::getEqualVar"]);
                                
                                        #如果執行失敗
                                        if($getEqualVar["status"]==="false"){
                                        
                                                #設置執行失敗
                                                $result["status"]="false";

                                                #設置錯誤訊息
                                                $result["error"]=$getEqualVar;

                                                #回傳結果
                                                return $result;
                                        
                                                }#if end
                                                
                                        #如果有找到對應的欄位位置
                                        if($getEqualVar["founded"]==="true"){
                                        
                                                #column Netid 的 index
                                                $indexOfColumnNetid=$getEqualVar["equalVarName"];
                                        
                                                #取得當前資料筆數
                                                $dataCount=count($result["content"]["Netid"]);
                                                
                                                #當前這筆資料的 Netid 內容
                                                $contentOfNetId=$result["content"]["Netid"][$dataCount-1];
                                        
                                                #判斷 Netid 的內容是否為 "u_" 開頭 
                                                #函式說明:
                                                #取得符合特定字首與字尾的字串
                                                #回傳結果:
                                                #$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
                                                #$result["function"],當前執行的函數名稱.
                                                #$result["error"],錯誤訊息陣列.
                                                #$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
                                                #$result["returnString"],爲符合字首條件的字串內容。
                                                #$result["argu"],使用的參數.
                                                #必填參數:
                                                #$conf["checkString"],字串,要檢查的字串.
                                                $conf["search::getMeetConditionsString"]["checkString"]=$contentOfNetId;
                                                #可省略參數:
                                                #$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
                                                $conf["search::getMeetConditionsString"]["frontWord"]="u_";
                                                #$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
                                                #$conf["tailWord"]="";
                                                #參考資料:
                                                #str_spilt(),可以將字串依照字母分割成一個個陣列字串。
                                                #備註:
                                                #無.
                                                $getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
                                                unset($conf["search::getMeetConditionsString"]);
                                                
                                                #如果執行失敗
                                                if($getMeetConditionsString["status"]==="false"){
                                                
                                                        #設置執行失敗
                                                        $result["status"]="false";

                                                        #設置錯誤訊息
                                                        $result["error"]=$getMeetConditionsString;

                                                        #回傳結果
                                                        return $result;
                                                
                                                        }#if end
                                                        
                                                #如果 Netid 的內容為 "u_" 開頭 
                                                if($getMeetConditionsString["founded"]==="true"){
                                                
                                                        #函式說明:
                                                        #將字串特定關鍵字與其後面的內容剔除
                                                        #回傳結果:
                                                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                                                        #$result["error"],錯誤訊息陣列.
                                                        #$result["warning"],警告訊息鎮列.
                                                        #$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
                                                        #$result["function"],當前執行的函數名稱.
                                                        #$result["oriStr"],要處理的原始字串內容.
                                                        #$result["content"],處理好的的字串內容.
                                                        #$result["argu"],使用的參數.
                                                        #必填參數:
                                                        #$conf["stringIn"],字串,要處理的字串.
                                                        $conf["stringProcess::delStrAfterKeyWord"]["stringIn"]=$data;
                                                        #$conf["keyWord"],字串,特定字串.
                                                        $conf["stringProcess::delStrAfterKeyWord"]["keyWord"]=" ";
                                                        #可省略參數:
                                                        #無.
                                                        #參考資料:
                                                        #無.
                                                        #備註:
                                                        #無.
                                                        $delStrAfterKeyWord=stringProcess::delStrAfterKeyWord($conf["stringProcess::delStrAfterKeyWord"]);
                                                        unset($conf["stringProcess::delStrAfterKeyWord"]);
                                                
                                                        #如果執行失敗
                                                        if($delStrAfterKeyWord["status"]==="false"){
                                                        
                                                                #設置執行失敗
                                                                $result["status"]="false";

                                                                #設置錯誤訊息
                                                                $result["error"]=$delStrAfterKeyWord;

                                                                #回傳結果
                                                                return $result;
                                                        
                                                                }#if end
                                                        
                                                        #如果有找到關鍵字
                                                        if($delStrAfterKeyWord["founded"]==="true"){
                                                        
                                                                #取得 socket 的檔案路徑與名稱
                                                                $data=$delStrAfterKeyWord["content"];
                                                        
                                                                }#if end
                                                
                                                        }#if end
                                                
                                                }#if end
                                                
                                        #debug
                                        #var_dump($result["columns"][$index],$data);
                                
                                        }#if end
                                
                                #如果是 "Process” 欄位的數值
                                else if($result["columns"][$index]==="Process"){
                                
                                        #可能的內容
                                        #users:(("sshd",pid=2920,fd=3))
                                        #users:(("httpd",pid=4221,fd=4),("httpd",pid=4038,fd=4),("httpd",pid=4037,fd=4),("httpd",pid=4036,fd=4),("httpd",pid=4035,fd=4),("httpd",pid=4033,fd=4))
                                        
                                        #函式說明:
                                        #取得符合特定字首與字尾的字串
                                        #回傳結果:
                                        #$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
                                        #$result["function"],當前執行的函數名稱.
                                        #$result["error"],錯誤訊息陣列.
                                        #$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
                                        #$result["content"],符合條件的字串,去掉字首字尾後的結果.
                                        #$result["returnString"],爲符合字首字、尾條件的字串內容。
                                        #$result["argu"],使用的參數.
                                        #必填參數:
                                        #$conf["checkString"],字串,要檢查的字串.
                                        $conf["search::getMeetConditionsString"]["checkString"]=$data;
                                        #可省略參數:
                                        #$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
                                        $conf["search::getMeetConditionsString"]["frontWord"]="users:(";
                                        #$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
                                        $conf["search::getMeetConditionsString"]["tailWord"]=")";
                                        #參考資料:
                                        #str_spilt(),可以將字串依照字母分割成一個個陣列字串。
                                        #備註:
                                        #無.
                                        $getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
                                        unset($conf["search::getMeetConditionsString"]);
                                
                                        #如果執行失敗
                                        if($getMeetConditionsString["status"]==="false"){
                                        
                                                #設置執行失敗
                                                $result["status"]="false";

                                                #設置錯誤訊息
                                                $result["error"]=$getMeetConditionsString;

                                                #回傳結果
                                                return $result;
                                        
                                                }#if end
                                                
                                        #如果有符合的內容
                                        if($getMeetConditionsString["founded"]==="true"){
                                        
                                                #debug
                                                #var_dump($getMeetConditionsString);
                                        
                                                #取得其內容
                                                #可能為:
                                                #("sshd",pid=2920,fd=3)
                                                #("httpd",pid=4221,fd=4),("httpd",pid=4038,fd=4),("httpd",pid=4037,fd=4),("httpd",pid=4036,fd=4),("httpd",pid=4035,fd=4),("httpd",pid=4033,fd=4)
                                                $processInfo=$getMeetConditionsString["content"];
                                        
                                                #解析 $processInfo
                                                #函式說明:
                                                #解析有規律的字串,分成多個段落.
                                                #回傳結果:
                                                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                                                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                                                #$result["function"],當前執行的函式名稱.
                                                #$result["argu"],使用的參數.
                                                #$result["content"],解析好的段落字串陣列.
                                                #$result["count"],解析好的段落數量.
                                                #必填參數:
                                                #$conf["input"],字串,要解析的內容.
                                                $conf["parser::section"]["input"]=$processInfo;
                                                #$conf["startSymbol"],字串,片段開始的識別字串.
                                                $conf["parser::section"]["startSymbol"]="(";
                                                #$conf["endSymbol"],字串,片段結束的識別字串.
                                                $conf["parser::section"]["endSymbol"]=")";
                                                #可省略參數:
                                                #$conf["splitSymbol"],字串,片段區隔的識別字串,預設為",".
                                                #$conf["splitSymbol"]=",";
                                                #參考資料:
                                                #無.
                                                #備註:
                                                #無.
                                                $section=parser::section($conf["parser::section"]);
                                                unset($conf["parser::section"]);
                                        
                                                #如果執行失敗
                                                if($section["status"]==="false"){
                                                
                                                        #設置執行失敗
                                                        $result["status"]="false";

                                                        #設置錯誤訊息
                                                        $result["error"]=$section;

                                                        #回傳結果
                                                        return $result;
                                                
                                                        }#if end
                                        
                                                #如果沒有資料
                                                if($section["count"]===0){
                                                
                                                        #設置執行失敗
                                                        $result["status"]="false";

                                                        #設置錯誤訊息
                                                        $result["error"]=$section;

                                                        #回傳結果
                                                        return $result;
                                                
                                                        }#if end
                                                
                                                #初始化程式名稱陣列
                                                $pNameArray=array();
                                                
                                                #"httpd",pid=4221,fd=4
                                                foreach($section["content"] as $pInfo){
                                                
                                                        #函式說明:
                                                        #解析有規律的字串,分成多個段落.
                                                        #回傳結果:
                                                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                                                        #$reuslt["error"],執行不正常結束的錯訊息陣列.
                                                        #$result["function"],當前執行的函式名稱.
                                                        #$result["argu"],使用的參數.
                                                        #$result["content"],解析好的段落字串陣列.
                                                        #$result["count"],解析好的段落數量.
                                                        #必填參數:
                                                        #$conf["input"],字串,要解析的內容.
                                                        $conf["parser::section"]["input"]=$pInfo;
                                                        #$conf["startSymbol"],字串,片段開始的識別字串.
                                                        $conf["parser::section"]["startSymbol"]="\"";
                                                        #$conf["endSymbol"],字串,片段結束的識別字串.
                                                        $conf["parser::section"]["endSymbol"]="\"";
                                                        #可省略參數:
                                                        #$conf["splitSymbol"],字串,片段區隔的識別字串,預設為",".
                                                        #$conf["splitSymbol"]=",";
                                                        #參考資料:
                                                        #無.
                                                        #備註:
                                                        #無.
                                                        $section=parser::section($conf["parser::section"]);
                                                        unset($conf["parser::section"]);
                                                
                                                        #如果執行失敗
                                                        if($section["status"]==="false"){
                                                        
                                                                #設置執行失敗
                                                                $result["status"]="false";

                                                                #設置錯誤訊息
                                                                $result["error"]=$section;

                                                                #回傳結果
                                                                return $result;
                                                        
                                                                }#if end
                                                
                                                        #如果不是只有一個程序的名稱
                                                        if($section["count"]!==1){
                                                        
                                                                #設置執行失敗
                                                                $result["status"]="false";

                                                                #設置錯誤訊息
                                                                $result["error"]=$section;

                                                                #回傳結果
                                                                return $result;
                                                        
                                                                }#if end
                                                
                                                        #記錄程式名稱
                                                        $pNameArray[]=$section["content"][0];
                                                
                                                        }#foreach end
                                                
                                                #更新成陣列
                                                $data=$pNameArray;
                                                
                                                }#if end
                                        
                                        }#if end
                        
                                #用欄位名稱來儲存資料
                                $result["content"][$result["columns"][$index]][]=$data;
                        
                                }#foreach end
                
                        }#foreach end
        
                #設置執行正常
                $result["status"]="true";
                
                #回傳結果
                return $result;
        
                }#function ss end

        /*
        #函式說明:
        #解析有規律的字串,分成多個段落.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #$result["argu"],使用的參數.
        #$result["content"],解析好的段落字串陣列.
        #$result["count"],解析好的段落數量.
        #必填參數:
        #$conf["input"],字串,要解析的內容.
        $conf["input"]="";
        #$conf["startSymbol"],字串,片段開始的識別字串.
        $conf["startSymbol"]="";
        #$conf["endSymbol"],字串,片段結束的識別字串.
        $conf["endSymbol"]="";
        #可省略參數:
        #$conf["splitSymbol"],字串,片段區隔的識別字串,預設為",".
        #$conf["splitSymbol"]=",";
        #參考資料:
        #無.
        #備註:
        #無.
        */
        public static function section(&$conf){
        
                #初始化要回傳的結果
                $result=array();
                
                #取得當前執行的函數名稱
                $result["function"]=__FUNCTION__;
                
                #如果 $conf 不為陣列
                if(gettype($conf)!="array"){
                        
                        #設置執行失敗
                        $result["status"]="false";
                        
                        #設置執行錯誤訊息
                        $result["error"][]="\$conf變數須為陣列形態";

                        #如果傳入的參數為 null
                        if($conf==null){
                                
                                #設置執行錯誤訊息
                                $result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
                                
                                }#if end

                        #回傳結果
                        return $result;
                        
                        }#if end
                
                #取得參數
                $result["argu"]=$conf;
                        
                #函式說明:
                #檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],執行不正常結束的錯訊息陣列.
                #$result["simpleError"],簡單表示的錯誤訊息.
                #$result["function"],當前執行的函式名稱.
                #$result["argu"],設置給予的參數.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
                #$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
                #$result["argu"],字串陣列,目前輸入的參數名稱陣列.
                #$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
                #$result["notNeedVar"],字串陣列,多餘的參數名稱.
                #必填參數:
                #$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck::checkArguments"]["varInput"]=&$conf;
                #$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可省略參數:
                #$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("input","startSymbol","endSymbol");
                #$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
                #$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
                $conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
                #$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
                #$conf["canNotBeEmpty"]=array();
                #$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
                #$conf["canBeEmpty"]=array();
                #$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
                $conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("splitSymbol");
                #$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["skipableVariableName"]=array("splitSymbol");
                #$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
                #$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(",");
                #$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
                #$conf["disallowAllSkipableVarIsEmpty"]="";
                #$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
                #$conf["disallowAllSkipableVarIsEmptyArray"]="";
                #$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["arrayCountEqualCheck"][]=array();
                #參考資料:
                #array_keys=>http://php.net/manual/en/function.array-keys.php
                #備註:
                #無.
                $checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);
        
                #如果執行失敗
                if($checkArguments["status"]==="false"){
                
                        #設置執行失敗
                        $result["status"]="false";

                        #設置錯誤訊息
                        $result["error"]=$checkArguments;

                        #回傳結果
                        return $result;
                
                        }#if end
                        
                #如果參數檢查不通過
                if($checkArguments["passed"]==="false"){
                
                        #設置執行失敗
                        $result["status"]="false";

                        #設置錯誤訊息
                        $result["error"]=$checkArguments;

                        #回傳結果
                        return $result;
                
                        }#if end
                        
                #初始化儲存段落結果的陣列
                $result["content"]=array();
                
                #初始化贊存的單一片段資料
                $tmpData="";
                        
                #初始化當前byte的形態,"start"代表開始符號;"end"代表結束符號;"data"代表內容.
                $byteType="";
                
                #針對每個byte
                for($i=0;$i<strlen($conf["input"]);$i++){
                
                        #debug
                        var_dump($conf["input"][$i],$tmpData);
                
                        #判斷每個字
                        switch($conf["input"][$i]){
                        
                                #如果是開始符號字串
                                case $conf["startSymbol"]:
                        
                                        #如果開始結尾的符號字串相同
                                        if($conf["startSymbol"]===$conf["endSymbol"]){
                                        
                                                #如果剛剛的資料是 data
                                                if($byteType==="data"){
                                                
                                                        #更新當前byte的形態
                                                        $byteType="end";
                                        
                                                        #保存該段落內容
                                                        $result["content"][]=$tmpData;
                                                        
                                                        #初始化新的段落內容
                                                        $tmpData="";
                                        
                                                        #結束 switch
                                                        break;
                                                
                                                        }#if end
                                        
                                                }#if end
                        
                                        #更新當前byte的形態
                                        $byteType="start";
                                        
                                        #初始化新的段落內容
                                        $tmpData="";
                        
                                        #結束 switch
                                        break;
                                        
                                #如果是結束符號字串
                                case $conf["endSymbol"]:
                        
                                        #更新當前byte的形態
                                        $byteType="end";
                        
                                        #保存該段落內容
                                        $result["content"][]=$tmpData;
                                        
                                        #初始化新的段落內容
                                        $tmpData="";
                        
                                        #結束 switch
                                        break;
                                        
                                #其他結果
                                default :
                                
                                        #代表為 data
                                        $byteType="data";
                        
                                        #串接段落內容
                                        $tmpData=$tmpData.$conf["input"][$i];
                        
                                }#switch end
                                
                        }#for end`
        
                #取得段落數量
                $result["count"]=count($result["content"]);
        
                #設置執行正常
                $result["status"]="true";
                
                #回傳結果
                return $result;
        
                }#function section end

        }#class parser end