在php編程中編程,取得當前url位址,以及伺服器變量,主要使用以下全域變數: $_server["query_string"],$_server["request_uri"],$_server["script_name"],$_server["php_self"] 1,$_server["query_string"] 說明:查詢(query)的字串 2,$_server["request_uri"] 說明:造訪此頁面所需的uri 3,$_server["script_name"] 說明:包含目前腳本的路徑 4,$_server["php_self"] 說明:目前正在執行腳本的檔案名 實例: 1,http://bbs.it-home.org/ (直接開啟首頁) 結果: $_server["query_string"] = "" $_server["request_uri"] = "/" $_server["script_name"] = "/index.php" $_server["php_self"] = "/index.php" 2,http://bbs.it-home.org/?p=222 (附查詢) 結果: $_server["query_string"] = "p=222" $_server["request_uri"] = "/?p=222" $_server["script_name"] = "/index.php" $_server["php_self"] = "/index.php" 3,http://bbs.it-home.org/index.php?p=222&q=biuuu 結果:
複製程式碼 複製程式碼複製程式碼
這些變數或函數的異同. 假設有一個請求位址為: http://localhost:8080/test.php/age=20 而test.php 的完整路徑是: d:/server/www/example/test.php 1)、getcwd() 將得到瀏覽器請求的頁面檔案所在的目錄. 即test.php 檔案所在的目錄: d:/server/www/example/ , 如果在test.php 執行了 require 或 include 語句, 例如 inculde(”test_dir/test2.php”), 那麼在 test2.php 裡 getcwd()函數 傳回的也會是 test.php 所在的目錄. 2)、__file__ 一個魔術變數, 用它將得到 __file__ 變數所在檔案的完整路徑, 例如: test.php 裡 __file__ 將會得到 d:/server/www/example/test.php , test_dir/test2.php 裡的 __file__ 會得到 d:/server/www/example/test_dir/test2.php 3)、$_server["script_filename"] 將會得到瀏覽器請求的頁面文件的完整路徑. test.php 和 test_dir/test2.php 裡用 $_server["script_name"] 都會得到 d:/server/www/example/test.php. 4)、$_server["script_name"] 將得到瀏覽器請求的頁面檔案的檔案名稱,注意: 與 $_server["script_name"] 不同, 此變數只得到檔案名稱而不包含路徑, 在test.php 與 test_dir/test2.php 用$_server["script_name"] 得到的都會是 test.php. 當然, 在test.php 與 test_dir/test2.php 執行 basename($_server["script_filename"]) 與 $_server["script_name"] 相同. 執行 在test.php 與 test_dir/test2.php 執行 realpath(”test.php”) 得到的結果與 $_server["script_filename"] 相同. 5)、$_server["php_self"] 將得到瀏覽器請求頁面的檔案名稱, 並剝掉問號 ? 後的內容, 注意:不包含路徑, 例如在客戶端請求 http://localhost:8080/test.php?age=20&name=tom, 那麼test.php 和 test_dir/test2.php 的 $_server["php_self"] 都會得到 “test.php”。 “age=20&name=tom”被剝掉。 而如果客戶端裡請求 http://localhost:8080/test.php/age=20&name=tom, 那麼test.php 和 test_dir/test2.php 的 $_server["php_self"] 都會得到 “test.php/age=20&name=tom”。 6)、$_server["request_uri"] 將會得到瀏覽器請求頁面的檔案名稱, 以及檔案名稱之後的所有內容(注意: 井號 # 之後的內容將會被略去), 例如在客戶端請求 http://localhost:8080/test.php?age=20&name=tom, 那麼test.php 和 test_dir/test2.php 的 $_server["reuest_uri"] 都會得到 “test.php”。 “age=20&name=tom”被剝掉。 而如果客戶端裡請求 http://localhost:8080/test.php/age=20&name=tom, 那麼test.php 和 test_dir/test2.php 的 $_server["request_uri"] 都會得到 “test.php/age=20&name=tom”。 test.php:
|

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP不是在消亡,而是在不斷適應和進化。 1)PHP從1994年起經歷多次版本迭代,適應新技術趨勢。 2)目前廣泛應用於電子商務、內容管理系統等領域。 3)PHP8引入JIT編譯器等功能,提升性能和現代化。 4)使用OPcache和遵循PSR-12標準可優化性能和代碼質量。

PHP的未來將通過適應新技術趨勢和引入創新特性來實現:1)適應云計算、容器化和微服務架構,支持Docker和Kubernetes;2)引入JIT編譯器和枚舉類型,提升性能和數據處理效率;3)持續優化性能和推廣最佳實踐。

在PHP中,trait適用於需要方法復用但不適合使用繼承的情況。 1)trait允許在類中復用方法,避免多重繼承複雜性。 2)使用trait時需注意方法衝突,可通過insteadof和as關鍵字解決。 3)應避免過度使用trait,保持其單一職責,以優化性能和提高代碼可維護性。

依賴注入容器(DIC)是一種管理和提供對象依賴關係的工具,用於PHP項目中。 DIC的主要好處包括:1.解耦,使組件獨立,代碼易維護和測試;2.靈活性,易替換或修改依賴關係;3.可測試性,方便注入mock對象進行單元測試。

SplFixedArray在PHP中是一種固定大小的數組,適用於需要高性能和低內存使用量的場景。 1)它在創建時需指定大小,避免動態調整帶來的開銷。 2)基於C語言數組,直接操作內存,訪問速度快。 3)適合大規模數據處理和內存敏感環境,但需謹慎使用,因其大小固定。

PHP通過$\_FILES變量處理文件上傳,確保安全性的方法包括:1.檢查上傳錯誤,2.驗證文件類型和大小,3.防止文件覆蓋,4.移動文件到永久存儲位置。

JavaScript中處理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。 1.??返回第一個非null或非undefined的操作數。 2.??=將變量賦值為右操作數的值,但前提是該變量為null或undefined。這些操作符簡化了代碼邏輯,提高了可讀性和性能。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

禪工作室 13.0.1
強大的PHP整合開發環境

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境