Subversion Repositories php-qbpwcf

Rev

Rev 239 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

/*

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2014~2026 MIN ZHI, 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 catchWebContent{

        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$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

        /*
        #函式說明:
        #抓取的特定網頁的某段內容
        #回傳的結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息陣列.
        #$result["function"],函數名稱.
        #$result["webContent"]["lineCount"],爲總共有機行原始碼。
        #$result["webContent"]["full"],爲抓取的全部網頁程式碼
        #$result["webContent"][i],爲第i+1行的程式碼
        #必填參數:
        #$conf["loadingPotision"],字串,要抓取的網頁網址
        $conf["loadingPotision"]="";#要抓取的網頁網址
        #可省略參數:
        #$conf["startLineNum"],從第幾行開始擷取,預設爲從第1行(第0個元素)。
        #$conf["startLineNum"]="";
        #$conf["endLineNum"],到第幾行結束截取,預設爲從最後一行(最後一個元素)。
        #$conf["endLineNum"]="";
        #$conf["processString"],爲是否要變更特定字串內容,預設爲false,不做變更,若設爲"true"則爲要進行處理字串的功能。
        #$conf["processString"]="";
        #$conf["selectedCharacter"],d爲被選擇要處理的字串/字元,須爲陣列值。
        #$conf["selectedCharacter"]=array("");
                #若不設定則預設爲要將這些字串作替換(" ","href","iframe","<",">","<a","/>",";","/","=","#",".","'","$","%","&","|")。
        #$conf["changeTo"],爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
        #$conf["changeTo"]=array("");
        #$conf["changeCharSet"],字元陣列,轉換全文編碼,預設不使用,$conf["changeCharSet"][0]為原始編碼,$conf["changeCharSet"][0]為新的編碼.
        #$conf["changeCharSet"]=array("big5","utf-8");
        #備註:
        #$conf["changeCharSet"]參數沒有效果.
        #有些網站會無法透過此方法取得網站內容.
        #參考資料:
        #iconv用法 => http://php.net/manual/en/function.iconv.php
        */
        public static function getFullWeb($conf){

                #初始化要回傳的變數
                $result=array();

                #取得當前函數名稱
                $result["function"]=__FUNCTION__;

                #初始化回傳的變數
                $result["webContent"]["full"]="";

                #如果 $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["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
                #$result["argu"],字串陣列,目前輸入的參數名稱陣列.
                #$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
                #$result["notNeedVar"],字串陣列,多餘的參數名稱.
                #必填寫的參數:
                #$conf["checkArguments::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["checkArguments::checkArguments"]["varInput"]=&$conf;
                #$conf["checkArguments::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["checkArguments::checkArguments"]["mustBeFilledVariableName"]=array("loadingPotision");
                #$conf["checkArguments::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
                $conf["checkArguments::checkArguments"]["mustBeFilledVariableType"]=array("string");
                #$conf["checkArguments::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["checkArguments::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$conf["checkArguments::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
                $conf["checkArguments::checkArguments"]["canBeEmptyString"]="false";
                #$conf["checkArguments::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["checkArguments::checkArguments"]["skipableVariableName"]=array("startLineNum","endLineNum","processString","selectedCharacter","changeTo");
                #$conf["checkArguments::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
                $conf["checkArguments::checkArguments"]["skipableVariableType"]=array("integer","integer","string","array","array");
                #$conf["checkArguments::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["checkArguments::checkArguments"]["skipableVarDefaultValue"]=array(0,null,"false",null,null);
                #$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["arrayCountEqualCheck"][]=array();
                #參考資料來源:
                #array_keys=>http://php.net/manual/en/function.array-keys.php
                $checkResult=variableCheck::checkArguments($conf["checkArguments::checkArguments"]);
                unset($conf["checkArguments::checkArguments"]);

                #如果檢查參數失敗
                if($checkResult["status"]=="false"){

                        #設置執行失敗
                        $result["status"]="false";

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

                        #回傳結果
                        return $result;

                        }#if end

                #將網頁原始碼依據行來存成陣列
                $webArrayContent=file($conf["loadingPotision"]);

                #如果取得網頁內容失敗
                if($webArrayContent==FALSE){

                        #設置執行失敗
                        $result["status"]="false";

                        #設置錯誤訊息
                        $result["error"][]="取得網頁內容失敗";

                        #回傳結果
                        return $result;

                        }#if end

                #計算總共有幾行
                $fileLines=count($webArrayContent);

                #如果$conf["endLineNum"]沒有設定
                if(!isset($conf["endLineNum"])){

                        #則預設爲最後一行
                        $conf["endLineNum"]=$fileLines;

                        }#if end

                #用迴圈將陣列印出來
                for($i=$conf["startLineNum"];$i<$conf["endLineNum"];$i++){

                        #如果 $conf["processString"] 爲 "true";
                        if($conf["processString"]=="true"){

                                #函式說明:
                                #處理字串避免網頁出錯
                                #回傳的結果:
                                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                                #$result["function"],當前執行的函數.
                                #$result["content"],爲處理好的字串.
                                #$result["error"],錯誤訊息陣列.

                                #則將特定的內容改變
                                $conf_correctCharacter["stringIn"]=$webArrayContent[$i];#爲要處理的字串

                                #如果 $conf["selectedCharacter"] 有設定則套用設定值
                                if(isset($conf["selectedCharacter"])){

                                        #爲被選擇要處理的字串/字元,須爲陣列值。
                                        $conf_correctCharacter["selectedCharacter"]=$conf["selectedCharacter"];

                                        }#if end

                                #如果 $conf["changeTo"] 有設定則套用設定值
                                if(isset($conf["changeTo"])){

                                        #爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
                                        $conf_correctCharacter["changeTo"]=$conf["changeTo"];

                                        }#if end

                                $correctCharacter=stringProcess::correctCharacter($conf_correctCharacter);
                                unset($conf_correctCharacter);#清空變數避免錯誤

                                #如果修正字串失敗
                                if($correctCharacter["status"]=="false"){

                                        #設置執行失敗
                                        $result["status"]="false";

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

                                        #回傳結果
                                        return $result;

                                        }#if end

                                #取得該行處理好的字串
                                $webArrayContent[$i]=$correctCharacter["content"];

                                }#if end

                        #則儲存該行的內容
                        $result["webContent"][$i]=$webArrayContent[$i];
                        $result["webContent"]["full"]=$result["webContent"]["full"].$webArrayContent[$i];

                        }#for end

                #儲存有幾行程式碼
                $result["webContent"]["lineCount"]=$fileLines;

                #/* 似乎沒有效果,所以先註解掉

                #如果 $conf["changeCharSet"][0、1] 有設定
                if(isset($conf["changeCharSet"][0]) && isset($conf["changeCharSet"][1])){

                        #將全文的編碼轉換
                        $result["webContent"]["full"]=iconv($conf["changeCharSet"][0],$conf["changeCharSet"][1],$result["webContent"]["full"]);

                        }#if end

                #*/

                #執行到這邊代表執行正常
                $result["status"]="true";

                #回傳變數內容
                return $result;

                }#function getFullWeb end

        /*
        #函式說明:
        #抓取的特定網頁的某段內容
        #回傳的結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息陣列.
        #$result["function"],函數名稱.
        #$result["oriWebContent"]["full"],原始檔案的完整內容.
        #$result["oriWebContent"]["byLine"],用陣列儲存的原始檔案逐行內容.
        #$result["oriWebContent"]["lineCount"],原始檔案的總共行數.
        #$result["webContent"]["lineCount"],爲總共有機行原始碼。
        #$result["webContent"]["full"],為檔案的完整內容,爲抓取的全部網頁程式碼
        #$result["webContent"][i],爲第i+1行的程式碼
        #必填參數:
        #$conf["loadingPotision"],字串,要抓取的網頁網址.
        $conf["loadingPotision"]="";
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["startLineNum"]="";#從第幾行開始擷取,預設爲從第1行(第0個元素)。
        #$conf["endLineNum"]="";#到第幾行結束截取,預設爲從最後一行(最後一個元素)。
        #$conf["processString"]="";#爲是否要變更特定字串內容,預設爲false,不做變更,若設爲"true"則爲要進行處理字串的功能。
        #$conf["selectedCharacter"]=array("");#爲被選擇要處理的字串/字元,須爲陣列值。
                #若不設定則預設爲要將這些字串作替換(" ","href","iframe","<",">","<a","/>",";","/","=","#",".","'","$","%","&","|")。
        #$conf["changeTo"]="";#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
        #參考資料:
        #無.
        #備註:
        #如果網址包含中文會出錯,網址若有空格也會失敗.
        */
        public static function wget(&$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["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$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["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("loadingPotision","fileArgu");
                #$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
                #$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
                #$conf["canBeEmptyString"]="false";
                #$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
                $conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("startLineNum","endLineNum","selectedCharacter");
                #$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["skipableVariableName"]=array("startLineNum","endLineNum","processString","selectedCharacter","changeTo");
                #$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","array","string");
                #$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"false",null,"");
                #$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["arrayCountEqualCheck"][]=array();
                #參考資料來源:
                #array_keys=>http://php.net/manual/en/function.array-keys.php
                $checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);

                #如果檢查失敗
                if($checkResult["status"]=="false"){

                        #設置執行失敗的識別
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$checkResult;

                        #回傳結果
                        return $result;

                        }#if end

                #如果檢查不通過
                if($checkResult["passed"]=="false"){

                        #設置執行失敗的識別
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$checkResult;

                        #回傳結果
                        return $result;

                        }#if end

                #建立暫存資料夾是否存在
                #函式說明:
                #建立資料夾,若要建立的資料夾所屬路徑不存在,則會自動嘗試建立,建立後的資料夾也可指定權限.
                #回傳的結果:
                #$result["status"],"true"爲建立成功,"false"爲建立失敗.
                #$result["error"],錯誤訊息陣列
                #必填參數:
                $conf["fileAccess::createFolderAfterCheck"]["dirPositionAndName"]=".catchWebContentTemp";#新建的位置與名稱
                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
                $conf["fileAccess::createFolderAfterCheck"]["fileArgu"]=$conf["fileArgu"];
                #可省略參數:
                #$conf["fileAccess::createFolderAfterCheck"]["dirPermission"]="";#新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
                #$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,預設為"false"不取消,若要取消該功能請設為"true".
                #$conf["fileAccess::createFolderAfterCheck"]["disableWebSearch"]="true";
                $callShell=fileAccess::createFolderAfterCheck($conf["fileAccess::createFolderAfterCheck"]);
                unset($conf["fileAccess::createFolderAfterCheck"]);

                #如果執行外部命令失敗
                if($callShell["status"]=="false"){

                        #設置執行失敗的識別
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$callShell;

                        #回傳結果
                        return $result;

                        }#if end

                #涵式說明:
                #取得系統時間目前的西元年、月、日、時、分、秒.
                #回傳的結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["thisWestYear"],當前西元年
                #$result["thisMonth"],當前月份
                #$result["weekDay"],為一個星期的第幾天,0代表第一天(星期日),6代表第七天(星期六)
                #$result["thisDay"],當前日
                #$result["thisHour"],當前小時
                #$result["thisMin"],當前分鐘
                #$result["thisSec"],當前秒數
                #必填參數:
                #$conf["time::getSystemDateAndTime"]["timeZone"],字串,時區代號,可以設定的時區列表:「http://www.php.net/manual/en/timezones.php」,台灣可用"Asia/Taipei".
                $conf["time::getSystemDateAndTime"]["timeZone"]="Asia/Taipei";
                #參考資料:
                #php的date函數用法=>http://php.net/manual/en/function.date.php
                $systemTime=time::getSystemDateAndTime($conf["time::getSystemDateAndTime"]);
                unset($conf["time::getSystemDateAndTime"]);

                #如果取得完整的系統時間失敗
                if($systemTime["status"]=="false"){

                        #設置執行失敗的識別
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$systemTime;

                        #回傳結果
                        return $result;

                        }#if end

                #初始化下載好的資料要放在哪裡,若有空格則會出錯
                $tempDownloadDFile=".catchWebContentTemp/".$systemTime["thisWestYear"]."-".$systemTime["thisMonth"]."-".$systemTime["thisDay"]."(".$systemTime["weekDay"].")"."_".$systemTime["thisHour"].":".$systemTime["thisMin"].":".$systemTime["thisSec"].".php";

                #轉換 $tempDownloadDFile       為正確的相對路徑
                #函式說明:
                #將多個路徑字串變成相對於當前路徑的相對路徑字串
                #回傳結果:
                #$result["status"],"true"爲建立成功,"false"爲建立失敗.
                #$result["error"],錯誤訊息陣列.
                #$result["function"],函數名稱.
                #$result["content"],字串陣列,多個轉換好的相對路徑字串.
                #必填參數:
                #$conf["path"],陣列字串,要轉換成相對路徑的字串.;
                $conf["fileAccess::getRelativePath"]["path"]=array($tempDownloadDFile);
                #$conf["fileArgu"],字串,當前路徑.
                $conf["fileAccess::getRelativePath"]["fileArgu"]=$conf["fileArgu"];
                $getRelativePath=fileAccess::getRelativePath($conf["fileAccess::getRelativePath"]);
                unset($conf["fileAccess::getRelativePath"]);

                #如果轉換路徑失敗
                if($getRelativePath["status"]==="false"){

                        #設置執行失敗的識別
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$getRelativePath;

                        #回傳結果
                        return $result;

                        }#if end

                #儲存轉換好的路徑
                $tempDownloadDFile=$getRelativePath["content"][0];

                #使用 wget 指令來下載網頁,要將擷取的結果儲存到檔案裡面
                #涵式說明:
                #呼叫shell執行系統命令,並取得回傳的內容.
                #回傳的結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息陣列
                #$result["output"],爲執行完二元碼後的輸出陣列
                #$result["function"],當前執行的函數名稱
                #必填的參數
                #$conf["external::callShell"]["command"],字串.
                $conf["external::callShell"]["command"]="wget";#要執行的指令與參數.
                #可省略參數:
                #$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
                $conf["external::callShell"]["argu"]=array("--no-check-certificate","-O",$tempDownloadDFile,$conf["loadingPotision"],"2>&1");
                #$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
                $conf["external::callShell"]["arguIsAddr"]=array("false","false","true","false","false");
                #$conf["external::callShell"]["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
                #$conf["external::callShell"]["enablePrintDescription"]="true";
                #$conf["external::callShell"]["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
                #$conf["external::callShell"]["printDescription"]="";
                #$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"true".
                $conf["external::callShell"]["escapeshellarg"]="true";
                $conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
                #參考資料:
                #http://php.net/manual/en/function.exec.php
                $callShell=external::callShell($conf["external::callShell"]);
                unset($conf["external::callShell"]);

                #如果執行外部命令失敗
                if($callShell["status"]==="false"){

                        #設置執行失敗的識別
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$callShell;

                        #回傳結果
                        return $result;

                        }#if end

                #然後將檔案內容存到變數裡面
                #函式說明:
                #依據行號分隔抓取檔案的內容,結果會回傳一個陣列
                #回傳的變數說明:
                #$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗。
                #$result["error"],錯誤訊息提示
                #$result["fileContent"],爲檔案的內容陣列
                #$result["lineCount"],爲檔案內容總共的行數
                #$result["fullContent"],為檔案的完整內容
                #必填參數:
                $conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$tempDownloadDFile;#爲檔案的位置以及名稱
                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
                $conf["fileAccess"]["getFileContent"]["fileArgu"]=$conf["fileArgu"];
                #參考資料:
                #file():取得檔案內容的行數
                #http:#php.net/manual/en/function.file.php
                $oriFileContent=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
                unset($conf["fileAccess"]["getFileContent"]);

                #如果 $result["oriWebContent"] 等於 "false"
                if($oriFileContent["status"]=="false"){

                        #代表取得檔案內容失敗
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$oriFileContent;

                        #回傳結果
                        return $result;

                        }#if end

                #原始檔案的完整內容
                $result["oriWebContent"]["full"]=$oriFileContent["fullContent"];

                #用陣列儲存的原始檔案逐行內容
                $result["oriWebContent"]["byLine"]=$oriFileContent["fileContent"];

                #原始檔案的總共行數
                $result["oriWebContent"]["lineCount"]=$oriFileContent["lineCount"];

                #移除暫存檔案
                #函式說明:
                #移除檔案
                #回傳的結果:
                #$result["status"],"true"代表移除成功,"false"代表移除失敗.
                #$result["error"],錯誤訊息陣列
                #$result["warning"],警告訊息陣列
                #$result["function"],當前執行的函數名稱
                #必填參數:
                $conf["fileAccess"]["delFile"]["fileAddress"]=$tempDownloadDFile;#要移除檔案的位置
                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
                $conf["fileAccess"]["delFile"]["fileArgu"]=$conf["fileArgu"];
                $fileDeleteResult=fileAccess::delFile($conf["fileAccess"]["delFile"]);
                unset($conf["fileAccess"]["delFile"]);

                #如果移除暫存檔案失敗
                if($fileDeleteResult["status"]=="false"){

                        #代表取得檔案內容失敗
                        $result["status"]="false";

                        #設置執行失敗的訊息
                        $result["error"]=$fileDeleteResult;

                        #回傳結果
                        return $result;

                        }#if end

                #如果 $conf["startLineNum"] 沒有設定
                if(!isset($conf["startLineNum"])){

                        #預測從第1行開始
                        $conf["startLineNum"]=1;

                        }#if end

                #如果 $conf["endLineNum"] 沒有設定
                if(!isset($conf["endLineNum"])){

                        #預測到最後1行
                        $conf["endLineNum"]=$result["oriWebContent"]["lineCount"];

                        }#if end

                #初始化要回傳的網頁擷取內容
                $result["webContent"]=array();

                #取得 $conf["startLineNum"] 到 $conf["endLineNum"] 的內容
                for($i=$conf["startLineNum"]-1;$i<$conf["endLineNum"];$i++){

                        #取得該行內容
                        $result["webContent"][]=$result["oriWebContent"]["byLine"][$i];

                        }#for end

                #取得行數
                $result["lineCount"]=count($result["webContent"]);

                #如果 $conf["processString"] 沒有設定
                if(!isset($conf["processString"])){

                        #則預設為 "false"
                        $conf["processString"]="false";

                        }#if end

                #如果 $conf["processString"] 等於 "fasle"
                if($conf["processString"]=="true"){

                        #剔除多餘的內容
                        #函式說明:
                        #處理多個字串避免網頁出錯
                        #回傳的結果:
                        #$result["status"],"true"代表執行成功,"false"代表執行失敗。
                        #$result["error"],錯誤訊息
                        #$result["processedStrArray"],處理好的字串陣列
                        #必填參數:
                        $conf["stringProcess"]["correctMutiStrCharacter"]["stringIn"]=$result["webContent"];#爲要處理的字串陣列
                        #可省略的參數:

                        #如果 #$conf["selectedCharacter"] 有設定
                        if(isset($conf["selectedCharacter"])){

                                #則套用設定值
                                $conf["stringProcess"]["correctMutiStrCharacter"]["selectedCharacter"]=$conf["selectedCharacter"];#爲被選擇要處理的字串/字元,須爲陣列值。
                                #若不設定則預設爲要將這些字串作替換(" ","href","iframe","<",">","<a","/>",";","/","=","#",".","'","$","%","&","|")。

                                }#if end

                        #如果 $conf["changeTo"] 有設定
                        if(isset($conf["changeTo"])){

                                #函式說明:
                                #建立一個陣列,可以指派陣列的內容,然後回傳
                                #回傳的結果:
                                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                                #$result["function"],當前執行的函數名稱.
                                #$result["error"],錯誤訊息陣列.
                                #$result["content"],爲陣列變數內容
                                #必填參數:
                                $conf["arrays::create"]["arrayContent"]=array($conf["changeTo"]);#陣列元素的內容,須爲陣列值。
                                #可省略參數:
                                $conf["arrays::create"]["arrayCounts"]=count($conf["selectedCharacter"]);#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
                                $conf["arrays::create"]["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
                                $createArray=arrays::create($conf["arrays::create"]);
                                unset($conf["arrays::create"]);

                                #如果建立陣列失敗
                                if($createArray["status"]=="false"){

                                        #代表取得檔案內容失敗
                                        $result["status"]="false";

                                        #設置執行失敗的訊息
                                        $result["error"]=$createArray;

                                        #回傳結果
                                        return $result;

                                        }#if end

                                #則套用設定值
                                #爲被選擇要處理的字串/字元,須爲陣列值。
                                $conf["stringProcess"]["correctMutiStrCharacter"]["changeTo"]=$createArray["content"];#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
                                        #若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
                                        #特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔

                                }#if end

                        $stringProcessResult=stringProcess::correctMutiStrCharacter($conf["stringProcess"]["correctMutiStrCharacter"]);
                        unset($conf["stringProcess"]["correctMutiStrCharacter"]);

                        #如果執行失敗
                        if($stringProcessResult["status"]=="false"){

                                #設置執行錯誤的識別
                                $result["status"]="false";

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

                                #回傳結果
                                return $result;

                                }#if end

                        #執行到這邊,代表執行成功
                        else{

                                #抓取處理好的內容
                                $result["webContent"]=$stringProcessResult["processedStrArray"];

                                }#else end

                        }#if end

                #初始化擷取的網頁全文
                $result["webContent"]["full"]="";

                #將每行串連起來
                for($i=0;$i<$result["lineCount"];$i++){

                        $result["webContent"]["full"]=$result["webContent"]["full"].$result["webContent"][$i];

                        }#for end

                #執行到這邊代表執行成功
                $result["status"]="true";

                #回傳結果
                return $result;

                }#function wget end

        /*
        #函式說明:
        #將特定網址的網頁內容儲存成html檔案
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #$result["html"],取得的網頁檔位置.
        #必填參數:
        #$conf["saveLocation"],字串,下載好的網頁要儲存到哪邊,副檔名會自動加上.
        $conf["saveLocation"]="";
        #$conf["webPageLocation"],字串,要下載的網頁目錄位置與檔案名稱.ex:「/about.php」,若是要下載首頁則可以用「/」.
        $conf["webPageLocation"]="";
        #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["type"],字串,網頁的協定,預設為"http",可以用的還有"https".
        #$conf["type"]="http";
        #$conf["webHostAddressOrDNS"],字串,網頁所處的IP或DNS,預設為"127.0.0.1".
        #$conf["webHostAddressOrDNS"]="127.0.0.1";
        #$conf["port"],字串,要使用的port,預設"80",一般來說http為80,https為443.
        #$conf["port"]="80";
        #參考資料:
        #無.
        #備註:
        #無.
        */
        public static function toHtml(&$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["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
                #必填寫的參數:
                #$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck.checkArguments"]["varInput"]=&$conf;
                #$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("saveLocation","webPageLocation","fileArgu");
                #$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
                $conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
                #$conf["variableCheck.checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
                #可以省略的參數:
                #$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
                #$conf["canBeEmptyString"]="false";
                #$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck.checkArguments"]["skipableVariableName"]=array("type","webHostAddressOrDNS","port");
                #$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
                $conf["variableCheck.checkArguments"]["skipableVariableType"]=array("string","string","string");
                #$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array("http","127.0.0.1","80");
                #$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["arrayCountEqualCheck"][]=array();
                $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

                #如果 $conf["type"] 不等於 "http" 與 "https"
                if($conf["type"]!="http" && $conf["type"]!="https"){

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

                        #設置執行錯誤訊息
                        $result["error"][]="不明的port:".$conf["type"];

                        #回傳結果
                        return $result;

                        }#if end

                #檢查儲存路徑是否存在
                #函式說明:
                #確保路徑存在.
                #回傳的結果:
                #$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息陣列.
                #$resutl["function"],當前執行的涵式名稱.
                #必填參數:
                #$conf["path"],要檢查的路徑
                $conf["fileAccess::validatePath"]["path"]=$conf["saveLocation"];
                #$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
                $conf["fileAccess::validatePath"]["fileArgu"]=$conf["fileArgu"];
                #可省略參數:
                #$conf["haveFileName"],字串,"true"代表有$conf["path"]檔案名稱,"false"代表$conf["path"]為純路徑,預設為"false".
                $conf["fileAccess::validatePath"]["haveFileName"]="true";
                #$conf["dirPermission"],字串,新建資料夾的權限設定,預設爲0770,亦即擁有者,同群組者可以讀,寫,存取,其他人僅能存取.
                #$conf["dirPermission"]="";
                $validatePath=fileAccess::validatePath($conf["fileAccess::validatePath"]);
                unset($conf["fileAccess::validatePath"]);

                #如果確保路徑失敗
                if($validatePath["status"]=="false"){

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

                        #設置執行錯誤訊息
                        $result["error"]=$validatePath;

                        #回傳結果
                        return $result;

                        }#if end

                #組合 wget 指令
                $paramsArray=array("--no-check-certificate","-O",$conf["saveLocation"].".html",$conf["type"]."://".$conf["webHostAddressOrDNS"].":".$conf["port"]."/".$conf["webPageLocation"]);

                #函式說明:
                #呼叫shell執行系統命令,並取得回傳的內容.
                #回傳結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息陣列.
                #$result["function"],當前執行的函數名稱.
                #$result["argu"],使用的參數.
                #$result["cmd"],執行的指令內容.
                #$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
                #$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
                #$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
                #$result["running"],是否還在執行.
                #$result["pid"],pid.
                #$result["statusCode"],執行結束後的代碼.
                #$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
                #必填參數:
                #$conf["command"],字串,要執行的指令.
                $conf["external.callShell"]["command"]="wget";
                #$conf["fileArgu"],字串,變數__FILE__的內容.
                $conf["external.callShell"]["fileArgu"]=__FILE__;
                #可省略參數:
                #$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
                $conf["external.callShell"]["argu"]=$paramsArray;
                #$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
                #$conf["arguIsAddr"]=array();
                #$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
                #$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
                #$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
                #$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
                #$conf["enablePrintDescription"]="true";
                #$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
                #$conf["printDescription"]="";
                #$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
                #$conf["escapeshellarg"]="false";
                #$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
                #$conf["thereIsShellVar"]=array();
                #$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
                #$conf["username"]="";
                #$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
                #$conf["password"]="";
                #$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
                #$conf["useScript"]="";
                #$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
                #$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
                #$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
                #$conf["inBackGround"]="";
                #$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
                #$conf["getErr"]="false";
                #$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
                #$conf["doNotRun"]="false";
                #參考資料:
                #exec=>http://php.net/manual/en/function.exec.php
                #escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
                #escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
                #備註:
                #不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
                #若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
                $callSell=external::callShell($conf["external.callShell"]);
                unset($conf["external.callShell"]);

                #如果執行 shell 失敗
                if($callSell["status"]=="false"){

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

                        #設置執行錯誤訊息
                        $result["error"]=$callSell;

                        #回傳結果
                        return $result;

                        }#if end

                #設置取得的網頁檔位置
                $result["html"]=$conf["saveLocation"].".html";

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

                #回傳結果
                return $result;

                }#toHtml function end

        /*
        #函式說明:
        #php內建的curl多執行序方法.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息.
        #$result["function"],當前執行的函數名稱.
        #$result["content"][$i]["info"],第$i+1個要求的回應資訊.
        #$result["content"][$i]["res"],第$i+1個要求的回應.
        #必填參數:
        #$conf["url"],字串陣列,有哪些網址要拜訪.
        $conf["url"]=array();
        #可省略參數:
        #$conf["opts"],一維字串陣列,要設定的curl連線參數,元素的key為參數的名稱,切記要為long形態(沒有""框住的文字),元素的value為參數的數值內容.
        #$conf["opts"];
        #參考資料:
        #curl_multi_ini(多執行緒執行curl)=>http://php.net/manual/en/function.curl-multi-init.php
        #$conf["opts"]可以用的參數=>http://php.net/manual/en/function.curl-setopt.php
        #等待與檢查curl_multi_exec還剩下幾個未執行完畢=>http://php.net/manual/en/function.curl-multi-select.php
        #備註:
        #重複執行會執行失敗
        */
        public static function nativeMulti(&$conf){

                #初始化要回傳的結果
                $result=array();

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

                #如果沒有參數
                if(func_num_args()==0){

                        #設置執行失敗
                        $result["status"]="false";

                        #設置執行錯誤訊息
                        $result["error"]="函數".$result["function"]."需要參數";

                        #回傳結果
                        return $result;

                        }#if end

                #取得參數
                $result["argu"]=$conf;

                #如果 $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["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$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["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url");
                #$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
                #$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$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["variableCheck::checkArguments"]["skipableVariableName"]=array("opts");
                #$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
                #$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
                #$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

                //create the multiple cURL handle
                $mh = curl_multi_init();

                #初始化儲存 curl handles 陣列的變數
                $ch=array();

                #建立多個 cURL resources
                for($i=0;$i<count($conf["url"]);$i++){

                        #儲存 初始化後的 curl handles
                        $ch[$i]=curl_init();

                        #設置curl要拜訪的網址
                        curl_setopt($ch[$i], CURLOPT_URL, $conf["url"][$i]);

                        #設置要將回應儲存到變數裡面
                        curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);

                        #設置連線的timeout
                        curl_setopt($ch[$i], CURLOPT_CONNECTTIMEOUT, 30);

                        #允許轉址
                        curl_setopt($ch[$i], CURLOPT_AUTOREFERER, true);

                        #設置連線允許的轉址次數
                        curl_setopt($ch[$i], CURLOPT_MAXREDIRS, 5);

                        #設置用戶端的資訊
                        curl_setopt($ch[$i], CURLOPT_USERAGENT, "qbpwcf-curl::native");

                        #不檢查 ssl 是否可信
                        curl_setopt($ch[$i], CURLOPT_SSL_VERIFYPEER, false);
                        curl_setopt($ch[$i], CURLOPT_SSL_VERIFYSTATUS, false);
                        curl_setopt($ch[$i], CURLOPT_SSL_VERIFYHOST, 0);

                        #如果有參數 $conf["opts"]
                        if(isset($conf["opts"])){

                                #依據每個參數
                                foreach($conf["opts"] as $optName => $optVal){

                                        #設置該參數
                                        $setopt=curl_setopt($ch[$i], $optName, $optVal);

                                        #如果參數設定失敗
                                        if($setopt===false){

                                                #設定執行失敗
                                                $result["status"]="false";

                                                #設定執行錯誤訊息
                                                $result["error"][]="參數「".$optName."」, 不存在或參數「".$optVal."」有誤。";

                                                #回傳結果
                                                return $result;

                                                }#if end

                                        }#foreach end

                                }#if end

                        #add the two handles
                        curl_multi_add_handle($mh,$ch[$i]);

                        }#for end

                #初始化儲存還有幾個連線未執行完畢
                $active = 0;

                #不斷地檢查是否有執行完畢
                do{

                        #執行每個curl連線
                        $mrc = curl_multi_exec($mh,$active);

                        #等一秒,回傳還剩下幾個連線未完成
                        $active=curl_multi_select($mh);

                        }#do end

                #如果還有連線未完成
                while($active>0);

                #有幾個 handles 就執行幾次
                for($i=0;$i<count($conf["url"]);$i++){

                        #取得回應
                        $res=curl_multi_getcontent($ch[$i]);

                        #取得每個 curl 要求的結果資訊陣列
                        $info=curl_getinfo($ch[$i]);

                        #儲存資訊與回應
                        $result["content"][]=array("info"=>$info,"res"=>$res);

                        #關閉 handles
                        curl_multi_remove_handle($mh, $ch[$i]);

                        }#for end

                #關閉 multi handles
                curl_multi_close($mh);

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

                #回傳結果
                return $result;

                }#function nativeMulti end

        /*
        #函式說明:
        #運行curl cmd
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$result["error"],錯誤訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #$result["founded"],識別網址找不找得到.
        #$result["content"],取得的回應內容陣列;若$conf["bgInProc"]為"true",則每個元素為其指令執行的結果訊息陣列,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"代表程序的資訊.
        #$result["fullContent"],取得回應的完整字串內容.
        #$result["cookie"],cookie檔案的位置與名稱.
        #$result["cmd"],執行的command.
        #$result["argu],使用的參數.
        #必填參數:
        #$conf["url"],字串,目標url.
        $conf["url"]="";
        #$conf["fileArgu"],字串,變數__FILE__的內容.
        $conf["fileArgu"]=__FILE__;
        #可省略參數:
        #$conf["header"],字串陣列,要傳送的header.
        #$conf["header"]=array();
        #$conf["allowAnySSLcertificate"],字串,是否允許不可信任的SSL憑證,預設為"true".
        #$conf["allowAnySSLcertificate"]="";
        #$conf["postVar"],字串陣列,每個要傳送的post變數名稱(陣列的key值)與數值.
        #$conf["postVar"]=array();
        #$conf["rawPost"]="字串",要傳送的raw post內容.
        #$conf["rawPost"]="";
        #$conf["urlEncode"],字串,post的內容是否要url_encode,"true"代表要,預設為"false"代表不要.
        #$conf["urlEncode"]="false";
        #$conf["agent"],字串,user agent的名稱.
        #$conf["agent"]="";
        #$conf["cookie"],字串,cookie位置與檔案位置.
        #$conf["cookie"]="";
        #$conf["forceNewCookie"],字串,是否要重置cookie,"true"代表要,"false"代表不要,預設為"false".
        #$conf["forceNewCookie"]="";
        #$conf["inBg"],字串,"true"代表要在背景中執行;反之則為"false".
        #$conf["inBg"]="true";
        #$conf["bgInPorc"],字串,若跟inBg一樣為"true",則會透過proc放在背景執行且回傳proc資訊,以便監控執行狀況.預設為"false",不使用proc.
        #$conf["bgInProc"]="false";
        #$conf["followRedirection"],字串,是否允許轉址,預設要為"true";反之為"false".
        #$conf["followRedirection"]="true";
        #參考資料:
        #無.
        #備註:
        #無.
        */
        public static function curlCmd(&$conf=array()){

                #初始化要回傳的結果
                $result=array();

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

                #如果沒有參數
                if(func_num_args()==0){

                        #設置執行失敗
                        $result["status"]="false";

                        #設置執行錯誤訊息
                        $result["error"]="函數".$result["function"]."需要參數";

                        #回傳結果
                        return $result;

                        }#if end

                #取得參數
                $result["argu"]=$conf;

                #如果 $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["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$reuslt["error"],執行不正常結束的錯訊息陣列.
                #$result["function"],當前執行的函式名稱.
                #$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
                #$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
                #$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
                #$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
                #必填寫的參數:
                #$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
                $conf["variableCheck::checkArguments"]["varInput"]=&$conf;
                #$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("url","fileArgu");
                #$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
                $conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
                #$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
                $conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
                #可以省略的參數:
                #$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
                $conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
                #$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
                #$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("followRedirection");
                #$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
                $conf["variableCheck::checkArguments"]["skipableVariableName"]=array("urlEncodeOnly","header","allowAnySSLcertificate","postVar","urlEncode","agent","cookie","forceNewCookie","rawPost","inBg","bgInProc","followRedirection");
                #$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
                $conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string","array","string","string","string","string","string","string","string","string");
                #$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
                $conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",array(),null,array(),"false",null,null,"false",null,"false","false","true");
                #$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
                #$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
                $checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
                unset($conf["variableCheck::checkArguments"]);

                #如果檢查參數失敗
                if($checkResult["status"]==="false"){

                        #設置執行失敗
                        $result["status"]="false";

                        #設置執行錯誤
                        $result["error"]=$checkResult;

                        #回傳結果
                        return $result;

                        }#if end

                #如果檢查參數不通過
                if($checkResult["passed"]==="false"){

                        #設置執行失敗
                        $result["status"]="false";

                        #設置執行錯誤
                        $result["error"]=$checkResult;

                        #回傳結果
                        return $result;

                        }#if end

                #要使用的參數
                $arguments=array();

                #是否不要用「"」保住參數
                $plainArgu=array();

                #改用「'」包住參數
                $useApostrophe=array();

                #判斷 $conf["url"] 為 http 還是 https
                #函式說明:
                #取得符合特定字首與字尾的字串
                #回傳的結果:
                #$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
                #$result["function"],當前執行的函數名稱.
                #$result["error"],錯誤訊息陣列.
                #$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
                #$result["returnString"],爲符合字首條件的字串內容。
                #必填參數:
                #$conf["checkString"],字串,要檢查的字串.
                $conf["search::getMeetConditionsString"]["checkString"]=$conf["url"];
                #可省略參數:
                #$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
                $conf["search::getMeetConditionsString"]["frontWord"]="https://";
                #$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

                #初始化沒有使用ssl
                $enableSSL="false";

                #如果有 https:// 關鍵字
                if($getMeetConditionsString["founded"]==="true"){

                        #如果未設定 $conf["allowAnySSLcertificate"]
                        if(!isset($conf["allowAnySSLcertificate"])){

                                #使用ssl
                                $enableSSL="true";

                                #預設為接受不可信任的ssl憑證
                                $conf["allowAnySSLcertificate"]="true";

                                }#if end

                        }#if end

                #如果有使用ssl
                if($enableSSL==="true"){

                        #設置 --ssl-reqd 參數,代表強制為https
                        $arguments[]="--ssl-reqd";

                        #要包住參數
                        $plainArgu[]="false";

                        #不要改用「'」包住參數
                        $useApostrophe[]="false";

                        #如果允許不被信任的憑證
                        if($conf["allowAnySSLcertificate"]==="true"){

                                #設置 -k 參數
                                $arguments[]="-k";

                                #要包住參數
                                $plainArgu[]="false";

                                #不要改用「'」包住參數
                                $useApostrophe[]="false";

                                }#if end

                        }#if end

                #針對每個 $conf["header"] 元素
                foreach($conf["header"] as $header){

                        #設置post參數
                        $arguments[]="-H";

                        #要包住參數
                        $plainArgu[]="false";

                        #不要改用「'」包住參數
                        $useApostrophe[]="false";

                        #設置post變數
                        $arguments[]=$header;

                        #要包住參數
                        $plainArgu[]="false";

                        #不要改用「'」包住參數
                        $useApostrophe[]="false";

                        }#foreach end

                #針對每個 $conf["postVar"] 元素
                foreach($conf["postVar"] as $name=>$value){

                        #如果沒有要」 url encode
                        if($conf["urlEncode"]==="false"){

                                #設置post參數
                                $arguments[]="-d";

                                #要包住參數
                                $plainArgu[]="false";

                                #不要改用「'」包住參數
                                $useApostrophe[]="false";

                                }#if end

                        #反之要 url encode
                        else{

                                #設置post參數
                                $arguments[]="--data-urlencode";

                                #要包住參數
                                $plainArgu[]="false";

                                #不要改用「'」包住參數
                                $useApostrophe[]="false";

                                }#else end

                        #設置post變數
                        $arguments[]=$name."=".$value;

                        #要包住參數
                        $plainArgu[]="false";

                        #不要改用「'」包住參數
                        $useApostrophe[]="false";

                        }#foreach end

                #如果有設置 $conf["rawPost"]
                if(isset($conf["rawPost"])){

                        #如果沒有要url encode
                        if($conf["urlEncode"]==="false"){

                                #設置post參數
                                $arguments[]="-d";

                                #要包住參數
                                $plainArgu[]="false";

                                #不要改用「'」包住參數
                                $useApostrophe[]="false";

                                #數值post vlaue
                                $arguments[]=$conf["rawPost"];

                                #要包住參數
                                $plainArgu[]="false";

                                #改用「'」包住參數
                                $useApostrophe[]="true";

                                }#if end

                        #反之要 url encode
                        else{

                                #設置post參數
                                $arguments[]="--data-urlencode";

                                #要包住參數
                                $plainArgu[]="false";

                                #不要改用「'」包住參數
                                $useApostrophe[]="false";

                                #數值post vlaue
                                $arguments[]=$conf["rawPost"];

                                #要包住參數
                                $plainArgu[]="false";

                                #改用「'」包住參數
                                $useApostrophe[]="true";

                                }#else end

                        }#if end

                #如果有設置 agent
                if(isset($conf["agent"])){

                        #使用agent參數
                        $arguments[]="-A";

                        #要包住參數
                        $plainArgu[]="false";

                        #不要改用「'」包住參數
                        $useApostrophe[]="false";

                        #設置agent參數值
                        $arguments[]=$conf["agent"];

                        #要包住參數
                        $plainArgu[]="false";

                        #不要改用「'」包住參數
                        $useApostrophe[]="false";

                        }#if end

                #遇到大於 400 的 http 回應要回傳異常
                $arguments[]="--fail";

                #要求的網址用 " " 包起來
                $arguments[]=$conf["url"];

                #要包住參數
                $plainArgu[]="false";

                #不要改用「'」包住參數
                $useApostrophe[]="false";

                #如果有設置 cookie 參數
                if(isset($conf["cookie"])){

                        #如果 cookie 檔案存在
                        if(file_exists($conf["cookie"])){

                                #如果沒有要重置cookie
                                if($conf["forceNewCookie"]==="false"){

                                        #設置使用既有的cookie
                                        $arguments[]="-b ".$conf["cookie"];

                                        #不要包住參數
                                        $plainArgu[]="true";

                                        #不要改用「'」包住參數
                                        $useApostrophe[]="false";

                                        }#if end

                                # 反之使用新的cookie
                                else{

                                        $arguments[]="-c ".$conf["cookie"];

                                        #不要包住參數
                                        $plainArgu[]="true";

                                        #不要改用「'」包住參數
                                        $useApostrophe[]="false";

                                        }#else end

                                }#if end

                        #反之不存在 cookie 檔案
                        else{

                                #設置使用新的cookie
                                $arguments[]="-c ".$conf["cookie"];

                                #不要包住參數
                                $plainArgu[]="true";

                                #不要改用「'」包住參數
                                $useApostrophe[]="false";

                                }#els end

                        }#if end

                #如果要允許轉址
                if($conf["followRedirection"]==="true"){

                        #follow redirection - start
                        $arguments[]="-L";

                        #不要包住參數
                        $plainArgu[]="true";

                        #不要改用「'」包住參數
                        $useApostrophe[]="false";

                        }#if end

                #要執行的command
                $cmd="curl";

                #如果要透過 proc 放在背景中運行
                if( $conf["inBg"]==="true" && $conf["bgInProc"]==="true" ){

                        #涵式說明:
                        #呼叫shell執行系統命令,並取得回傳的內容.
                        #回傳的結果:
                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                        #$result["error"],錯誤訊息陣列.
                        #$result["function"],當前執行的函數名稱.
                        #$result["argu"],使用的參數.
                        #$result["cmd"],執行的指令內容.
                        #$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
                        #$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
                        #$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
                        #$result["running"],是否還在執行.
                        #$result["pid"],pid.
                        #$result["statusCode"],執行結束後的代碼.
                        #$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
                        #必填的參數
                        #$conf["command"],字串,要執行的指令與.
                        $conf["external::callShell"]["command"]=$cmd;
                        #$conf["fileArgu"],字串,變數__FILE__的內容.
                        $conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
                        #可省略參數:
                        #$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
                        $conf["external::callShell"]["argu"]=$arguments;
                        #$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
                        #$conf["arguIsAddr"]=array();
                        #$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",元算若為"true"則代表不用包;反之"false"則代表要包.
                        #$conf["external::callShell"]["plainArgu"]=$plainArgu;
                        #$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
                        #$conf["external::callShell"]["useApostrophe"]=$useApostrophe;
                        #$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
                        #$conf["external::callShell"]["enablePrintDescription"]="true";
                        #$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
                        #$conf["printDescription"]="";
                        #$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
                        $conf["external::callShell"]["escapeshellarg"]="true";
                        #$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
                        #$conf["username"]="";
                        #$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
                        #$conf["password"]="";
                        #$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
                        #$conf["useScript"]="";
                        #$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
                        #$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
                        #$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
                        #$conf["external::callShell"]["inBackGround"]=$conf["inBg"];
                        #$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
                        #$conf["getErr"]="false";
                        #$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
                        $conf["external::callShell"]["doNotRun"]="true";
                        #備註:
                        #不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
                        #參考資料:
                        #exec=>http://php.net/manual/en/function.exec.php
                        #escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
                        #escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
                        $callShell=external::callShell($conf["external::callShell"]);
                        unset($conf["external::callShell"]);

                        #如果尋找關鍵字失敗
                        if($callShell["status"]==="false"){

                                #設置執行失敗
                                $result["status"]="false";

                                #設置執行錯誤
                                $result["error"]=$callShell;

                                #回傳結果
                                return $result;

                                }#if end

                        #初始化要透過proc執行的指令
                        $cmdAndArguForThreadsProc=$callShell["escape"]["array"];

                        #函式說明:
                        #透過proc來多執行序運作.
                        #回傳結果:
                        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                        #$reuslt["error"],執行不正常結束的錯訊息陣列.
                        #$result["function"],當前執行的函式名稱.
                        #$result["argu"],使用的參數.
                        #$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"代表程序的資訊.
                        #必填參數:
                        #$conf["cmds"],字串陣列,每個元素代表要執行的指令與參數.
                        $conf["threads::proc"]["cmds"]=array($cmdAndArguForThreadsProc);
                        #可省略參數:
                        #$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
                        $conf["threads::proc"]["wait"]="true";
                        #$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
                        #$conf["workingDir"]=array("path");
                        #$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
                        #$conf["envs"]=array(array("key"=>"value"));
                        #$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
                        #$conf["executeBy"]=array("bash");
                        #參考資料:
                        #https://www.php.net/manual/en/function.proc-open.php
                        #https://www.php.net/manual/en/function.proc-get-status.php
                        #備註:
                        #無.
                        $proc=threads::proc($conf["threads::proc"]);
                        unset($conf["threads::proc"]);

                        #如果尋找關鍵字失敗
                        if($proc["status"]==="false"){

                                #設置執行失敗
                                $result["status"]="false";

                                #設置執行錯誤
                                $result["error"]=$proc;

                                #回傳結果
                                return $result;

                                }#if end

                        #取得 proc 資訊
                        $result["content"]=$proc["content"];

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

                        #回傳結果
                        return $result;

                        }#if end

                #涵式說明:
                #呼叫shell執行系統命令,並取得回傳的內容.
                #回傳的結果:
                #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
                #$result["error"],錯誤訊息陣列.
                #$result["function"],當前執行的函數名稱.
                #$result["cmd"],執行的指令內容.
                #$result["output"],爲執行完二元碼後的輸出陣列.
                #$result["pid"],pid
                #$result["statusCode"],執行結束後的代碼.
                #必填的參數
                #$conf["command"],字串,要執行的指令與.
                $conf["external::callShell"]["command"]=$cmd;
                #$conf["fileArgu"],字串,變數__FILE__的內容.
                $conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
                #可省略參數:
                #$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
                $conf["external::callShell"]["argu"]=$arguments;
                #$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
                #$conf["arguIsAddr"]=array();
                #$conf["plainArgu"],字串陣列,哪幾個參數不要加上"",元算若為"true"則代表不用包;反之"false"則代表要包.
                #$conf["external::callShell"]["plainArgu"]=$plainArgu;
                #$conf["useApostrophe"],字串陣列,如果有需要包住,則用「'」,而非「"」處理.前者為"true";後者為"false".
                #$conf["external::callShell"]["useApostrophe"]=$useApostrophe;
                #$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
                #$conf["external::callShell"]["enablePrintDescription"]="true";
                #$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
                #$conf["printDescription"]="";
                #$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
                $conf["external::callShell"]["escapeshellarg"]="true";
                #$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
                #$conf["username"]="";
                #$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
                #$conf["password"]="";
                #$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
                #$conf["useScript"]="";
                #$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
                #$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
                #$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
                $conf["external::callShell"]["inBackGround"]=$conf["inBg"];
                #備註:
                #不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
                #參考資料:
                #exec=>http://php.net/manual/en/function.exec.php
                #escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
                #escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
                $callShell=external::callShell($conf["external::callShell"]);
                unset($conf["external::callShell"]);

                #預設網址找不到
                $result["founded"]="false";

                #如果執行失敗
                if($callShell["status"]==="false"){

                        #如果不是response header >= 400
                        if($callShell["statusCode"]!==22){

                                #設置執行失敗
                                $result["status"]="false";

                                #設置執行錯誤
                                $result["error"]=$callShell;

                                #回傳結果
                                return $result;

                                }#if end

                        }#if end

                #反之
                else{

                        #設置網址找到
                        $result["founded"]="true";

                        }#else end

                #儲存得到的回應
                $result["content"]=$callShell["output"];

                #初始化完整回應為空字串
                $result["fullContent"]="";

                #針對每列回應
                foreach($result["content"] as $line){

                        #串接結果
                        $result["fullContent"]=$result["fullContent"].$line;

                        }#foreach end

                #儲存執行的command
                $result["cmd"]=$callShell["cmd"];

                #如果有設置 cookie 檔案
                if(isset($conf["cookie"])){

                        #回傳 cookie 檔案的位置與名稱
                        $result["cookie"]=$conf["cookie"];

                        }#if end

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

                #回傳結果
                return $result;

                }#function curlCmd end

        }#class catchWebContent end

?>