為什么?我需要檢測給定的路徑是否包含目錄,app但僅在站點的根目錄之后(即忽略完整的服務器路徑,只搜索實際站點內的路徑)。考慮以下路徑:/root/var/www/app/app/Http 真的/root/var/www/app/public 錯誤的C:\Users\john\Sites\example_com\www\app\Http 真的我嘗試過的...我已經使用以下代碼解決了上述問題:// Normalise the directory separators in the document// root$document_root = str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT']);// Remove the '/public' path from the end, this should // give us the path to the site root...$site_root = str_replace(DIRECTORY_SEPARATOR . 'public', '', $document_root);// Normalise the directory separators in the supplied// path$normalised_path = str_replace('/', DIRECTORY_SEPARATOR, $path['path']);// Remove the site root from the beginning of the path$stripped_path = str_replace($site_root, '', $normalised_path);// Now we can run our tests...我的問題是我還是上面的代碼對于這樣一個簡單的任務來說似乎很荒謬?任何人都可以提出更好或更清潔的方法來實現這一目標嗎?本質上,我試圖從給定的路徑中剝離服務器根目錄,以便為我提供一個相對于站點根目錄的路徑......如果有一種方法可以使用 Laravel/Lumen 中的內置類/方法來實現這一點,那么也請隨時提出這些建議。
- 1 回答
- 0 關注
- 144 瀏覽
添加回答
舉報
0/150
提交
取消