<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                1.DIRECTORY\_SEPARATOR php目錄分隔符:\ 在windows我們習慣性的使用“\\”作為文件分隔符,但是在linux上系統不認識這個標識,于是就要引入這個php內置變量了:DIRECTORY_SEPARATOR 1.5**PHP_EOL**為換行符。 2.# PHP常量PHP_SAPI與函數php_sapi_name()簡介,PHP運行環境檢測 (1)PHP_SAPI 用來判斷是使用命令行還是瀏覽器執行的,如果 PHP_SAPI==’cli’ 表示是在命令行下執行 php判斷解析php服務是由那種服務器軟件,是采用那種協議 直接輸出即可 代碼如下: <?php echo PHP_SAPI; ?> 我的測試環境是nginx+fastcgi 輸出結果為: cgi-fcgi 如果是apache 運行環境,輸出結果為 apache2handler 如果是命令行的形式執行,結果為 cli 這就是PHP_SAPI (2)php_sapi_name() 是用來檢測PHP運行環境的函數 例如,CLI 的 PHP 下這個字符串會是 “cli”,Apache 下可能會有幾個不同的值,取決于具體使用的 SAPI。 以下列出了可能的值: aolserver、apache、 apache2filter、apache2handler、 caudium、cgi (直到 PHP 5.3), cgi-fcgi、cli、 continuity、embed、 isapi、litespeed、 milter、nsapi、 phttpd、pi3web、roxen、 thttpd、tux 和 webjames。 3. die()停止程序運行,輸出內容 exit是停止程序運行,不輸出內容 return是返回值 return:執行到該處退出,如果是在函數中,表示退出函數,如果是在腳本中,表示腳本停止執行 die是遇到錯誤才停止 exit是直接停止,并且不運行后續代碼,exit()可以顯示內容,例如exit('dsdsdsdf')。 exit(0):正常運行程序并退出程序; exit(1):非正常運行導致退出程序; 4 dirname() 函數返回路徑中的目錄部分 D:\\phpstudy\\PHPTutorial\\WWW\tp5\public 再一次:D:\\phpstudy\\PHPTutorial\\WWW\tp5 再一次:D:\\phpstudy\\PHPTutorial\\WWW 5. realpath() 函數返回絕對路徑。 該函數刪除所有符號連接(比如 '/./', '/../' 以及多余的 '/'),返回絕對路徑名。 6.spl_autoload_register() ``` <? class test { public static function loadprint( $class ) { $file = $class . '.class.php'; if (is_file($file)) { require_once($file); } } } spl_autoload_register( array('test','loadprint') ); //另一種寫法:spl_autoload_register( "test::loadprint" ); $obj = new PRINTIT(); $obj->doPrint();?> PRINTIT::doPrint() 同樣會加載 PRINTIT.php文件 用法: require_once('A.php'); \A::regist(); //注冊自動加載 echo \User::test();//自動加載User.php文件 ``` 7. 'think\\Loader::autoload' 表示:'think\Loader::autoload' \\轉義字符,表示'\' 8.property_exists 主要作用是判斷類或對象中的屬性是否存在,存在是為true,不存在是false bool interface_exists (string $interface_name [, bool $autoload = true ]) 判斷接口是否存在 bool class_exists (string $class_name [, bool $autoload = true ]) 判斷類是否存在 bool method_exists (mixed $object , string $method_name) 判斷指定類或者對象中是否含有指定的成員函數 bool property_exists (mixed $class , string $property) 判斷指定類或者對象中是否含有指定的成員變量。 function_exists()檢測函數是否存在 is_callable )檢測函數是否匿名函數 **function\_exists 比較簡單點就是判斷函數有沒有被定義 而method\_exists 是判斷類內的方法存不存在 ?is\_callable?檢測參數是否為合法的可調用結構** ``` class Obj{ public $is_public; protected $is_protected; private $is_private; public static $is_public_static; const is_const=3; } $obj = new Obj(); var_dump(property_exists('Obj','is_public')); //true; var_dump(property_exists($obj,'is_public')); //true; var_dump(property_exists($obj,'is_protected')); //true; var_dump(property_exists($obj,'is_private')); //true; var_dump(property_exists($obj,'is_public1')); //false; var_dump(property_exists($obj,'is_public_static')); //true; var_dump(property_exists('Obj','is_const')); //false; ``` 9. ``` [0=>'sasas'] 另一種寫法:(array)'sasas' ``` 10 ``` var_dump(facade\App::class); 輸出結果為: "app\index\controller\facade\App" ‘app\index\controller\’為所在文件的命名空間 ``` 11. strtr() 函數 ``` 把字符串中的字符 "ia" 替換為 "eo": <?php echo strtr("Hilla Warld","ia","eo"); ?> ``` 12. ``` $str='adafadsfadsff'; echo $str[0]; 輸出結果:a; ``` 13. microtime() 函數返回當前 Unix 時間戳的微秒數。 ucwords() 函數把字符串中每個單詞的首字符轉換為大寫 ucfirst() 函數把字符串中的首字符轉換為大寫 lcfirst() - 把字符串中的首字符轉換為小寫 strtolower() 函數把字符串轉換為小寫 strtoupper() 函數把字符串轉換為大寫 strpos() 函數查找字符串在另一字符串中第一次出現的位置。 strrpos() 函數查找字符串在另一字符串中最后一次出現的位置。 查找 "php" 在字符串中最后一次出現的位置: echo strrpos("You love php, I love php too!","php"); stristr() 函數搜索字符串在另一字符串中的第一次出現,并返回字符串的剩余部分 strstr() 函數搜索字符串在另一字符串中的第一次出現并,返回字符串的剩余部分,對大小寫敏感 trim() 函數移除字符串兩側的空白字符或其他預定義字符。 ltrim() - 移除字符串左側的空白字符或其他預定義字符 rtrim() - 移除字符串右側的空白字符或其他預定義字符 realpath() 函數返回絕對路徑,該函數刪除所有符號連接(比如 '/./', '/../' 以及多余的 '/'),返回絕對路徑名。若失敗,則返回 false。比如說文件不存在的話。 scandir() 函數以數組形式返回指定目錄中的文件和目錄 strtr() 函數轉換字符串中特定的字符。strtr("Hilla Warld","ia","eo"); str_replace() 函數以其他字符替換字符串中的一些字符(區分大小寫) str_replace("world","Shanghai","Hello world!");把字符串 "Hello world!" 中的字符 "world" 替換為 "Shanghai"; 14 memory_get_usage()函數返回內存使用量,memory_get_peak_usage()函數返回內存使用峰值,getrusage()返回CUP使用情況。但有一點請注意,在這些函數需要在Linux上運行 15. $declaredClass = get_declared_classes(); 獲取當前加載的所有類 $composerClass = array_pop($declaredClass); 刪除數組中的最后一個元素,返回值是最后一個元素 16. pathinfo(path,options)函數以數組的形式返回文件路徑的信息。 * PATHINFO_DIRNAME - 只返回 dirname * PATHINFO_BASENAME - 只返回 basename * PATHINFO_EXTENSION - 只返回 extension * PATHINFO_FILENAME-只返回 FILENAME ``` <?php print_r(pathinfo("/testweb/test.txt")); ?> ~~~ Array ( [dirname] => /testweb [basename] => test.txt [extension] => txt [filename] => test ) ~~~ ``` 17. key() 函數返回數組內部指針當前指向元素的鍵名 reset() 函數將內部指針指向數組中的第一個元素,并輸出。 18.# call_user_func_array函數詳解 call_user_func函數詳解 把第一個參數作為回調函數(**callback**)調用,把參數數組作(**param_arr**)為回調函數的的參數傳入 ``` 代碼如下: (1)普通使用: ? ? ? ? ? ?function a($b, $c)?{ ? ? ? ? ? ? ? ? ? echo $b;? ? ? ? ? ? ? ? ? echo $c;? ? ? ? ? ? ?}? ? ? ? ? ? call_user_func_array('a', array("111", "222"));? ? ? ? ? ? //輸出?111 222 (2)調用類內部的方法: ? ? ? ? ?Class ClassA?{? ? ? ? ? ? ? ? ?function bc($b, $c) {? ? ? ? ? ? ? ? ? ? $bc = $b + $c;? ? ? ? ? ? ? ? ? ? echo $bc;? ? ? ? ? ? ? ? ? ?}? ? ? ? ? ? ? }? ? ? ? ? ? call_user_func_array(array('ClassA','bc'), array("111", "222"));? ? ? ? ? ? //輸出? 333? (3)支持引用傳遞: ? ? ? ? ? function a(&$b)?{? ? ? ? ? ? ? ? $b++;? ? ? ? ? ? }? ? ? ? ? ? $c = 1;? ? ? ? ? ? call_user_func_array('a', array(&$c));? ? ? ? ? ? echo $c; ?//輸出?2? ``` 19. **func\_get\_args():返回一個包含函數參數列表的數組。** **func\_get\_arg():返回指定的參數值。** **func\_num\_args():返回調用函數的傳入參數個數,類型是整型** ``` public function test(){ $res= $this->hello(1,2,3,4); var_dump($res); } public function hello($a,$b,$c,$d){ $num=func_num_args(); $num2=func_get_arg(2); $num3=func_get_args(); return $num3; } 打印結果分別是:4,3,array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) } ``` 20# __CLASS__、get_class()與get_called_class()都是獲取當前類名,完整類名,包含命名空間 區別: ![](https://img.kancloud.cn/ca/15/ca15d20e46f40089260122011b6cf14b_672x458.png) 21 php 5.3 后新增了__call與__callStatic魔法方法。 __call當要調用的方法不存在或權限不足時,會自動調用__call 方法。 __callStatic當調用的靜態方法不存在或權限不足時,會自動調用__callStatic方法。 ``` public function __call($func, $arguments){ } public function __callStatic($func, $arguments){ } ``` 22.錯誤方面的函數 ~~~ // 關閉錯誤報告 error_reporting(0); // 報告 runtime 錯誤 error_reporting(E_ERROR | E_WARNING | E_PARSE); // 報告所有錯誤 error_reporting(E_ALL); // 等同 error_reporting(E_ALL); ini_set("error_reporting", E_ALL); // 報告 E_NOTICE 之外的所有錯誤 error_reporting(E_ALL & ~E_NOTICE); ~~~ ``` 通過 set\_error\_handler() 函數設置用戶自定義的錯誤處理程序,然后觸發錯誤(通過 trigger\_error()): set\_error\_handler("customError") 不僅可以接受**函數**,還可以接受**類的方法(公開的靜態方法 及 公開的非靜態方法 都可以)**,但需要以**數組形式**傳遞,數組的第一值為“類名”,第二個參數為“方法名”, ``` ``` set\_exception\_handler() 函數設置用戶定義的異常處理函數。 set_exception_handler([__CLASS__, 'appException']); ``` ``` 當PHP程序執行完成后,自動執行register\_shutdown\_function函數,該函數需要一個參數,用來指定由誰處理這些后續的工作。其中,**程序執行完成**,分為以下幾種情況: 第一種:php代碼執行過程中發生錯誤 第二種:php代碼順利執行成功 第三種:php代碼運行超時 第四種:頁面被用戶強制停止 register_shutdown_function([__CLASS__, 'appShutdown']); ``` 23. get_object_var($object) 返回類中所有的非靜態方法和非靜態屬性 24.array_change_key_case() 函數將數組的所有的鍵都轉換為大寫字母或小寫字母。 * CASE_LOWER - 默認值。將數組的鍵轉換為小寫字母。 * CASE_UPPER - 將數組的鍵轉換為大寫字母 25uniqid(prefix,more_entropy) uniqid() 函數基于以微秒計的當前時間,生成一個唯一的 ID。 prefix 可選。為 ID 規定前綴。如果兩個腳本恰好在相同的微秒生成 ID,該參數很有用。 more_entropy 可選。規定位于返回值末尾的更多的熵。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看