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