PHP知識點小結

來源:互聯網
上載者:User
PHP知識點總結

?1.?DIRECTORY_SEPARATOR

?

?? ? ? 因為在window上分隔字元是"\"而在linux上分隔字元是"/" ?使用這個符號就可以避免這個問題。

?

?2.?realpath

?

?? ? ?返迴文件所在的絕對路徑。

?

?3. 在php中 0==null 是成立的。?? ?

?

?4.file_get_contents和file區別

?

?? ? ? ?file_get_contents將檔案內容作為一個字串返回

?? ? ? ?file ?將檔案內容按行讀取到一個數組中,一行就是數組中的一項。

?

count(file("test.txt"))//獲得檔案的行數

?

?

?5. php刪除檔案夾 (如果有檔案夾不為空白第一次跑這個檔案可能會報錯,第二次就可以了)

?

function deleteDir($dir){    if(rmdir($dir)==false&&is_dir($dir)){          if($filehandler=opendir($dir)){                 while(($file=readdir($filehandler))!=false){                       if($file!="."&&$file!=".."){                              $fullpath = $dir."/".$file;                             if(is_dir($fullpath)){                                     deleteDir($fullpath);                             }else{                                     unlink($fullpath);                             }                        }                 }                 closedir($filehandler);          }else{                echo "permision deny";          }     }}

?

6. ?json_encode和json_decode

?

?? ? ? ? ? ?json_encode() ? : ?將一個php對象轉化為json格式的字串

?

?? ? ? ? ? ?json_decode($str,$boolean) ?: ?將json格式字串轉化為一個php對象,如果$boolean為true則返回一個數組。 注意$str的格式一定要正確,key一定要有雙引號,否則轉化失敗。

?

?7. ?php字串串連使用 .= 符號,不是+=符號。


?8. ?__FILE__ 取得當前檔案的絕對位址。

?

?9. ?首先開啟php.ini,將zend_extension = "D:\develop\xampp\php\ext\php_xdebug.dll"開啟,同時[xdebug]設定項開啟相 ? ? ? ? ? 關的設定,只要是 xdebug.remote_enable = On 要開啟,不然無法調試。php.ini的xdebug設定如下:、

?

xdebug.remote_enable=1xdebug.remote_autostart=1xdebug.remote_mode=reqxdebug.remote_host=localhostxdebug.remote_port=9000xdebug.idekey=PhpStorm1
?

?? 設定完畢,啟動PhpStorm,我們使用開啟目錄功能,這裡的目錄最好是xampp的htdocs下的一個目錄,這樣我們就可以Just-in-Time 偵錯程式。接下來我們要開啟設定面板,然後選擇php,設定正確的php home路徑,這裡就可以進行php相關的單元測試等。

?

? ?注意xampp安裝的路勁不能有空格,不識別。

?

?10. ?php發送郵件 主題亂碼解決

?

?

$subject = iconv("","UTF-8","Gaea");$subject = "=?UTF-8?B?".base64_encode($subject)."?="; //轉化成base64
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.