我還在學習php。你如何提取根目錄?
'SCRIPT_FILENAME' => string 'D:/Project Storage/wnmp/www/folder/index.php' (length=45)
'SCRIPT_NAME' => string '/folder/index.php' (length=18)
'DOCUMENT_URI' => string '/folder/index.php' (length=18)
'PHP_SELF' => string '/folder/index.php' (length=18)
'REQUEST_URI' => string '/folder/helloworld/helloworldtwo/etc' (length=15)
,你可以看到,我只是想獲得helloworld/helloworldtwo/etc
任何想法解壓文件夾?所以它會是helloworld/helloworldtwo/etc
?
即時通訊的想法是即時定義我的文件夾,如$root = 'folder'
。那麼我提取它,如果它匹配,但問題是什麼?
第二個想法是從php_self或任何上面得到第一個從/first/second.php, 但我不知道最好的方式來做到這一點。
另一個問題是當我們在前面有兩個文件夾時?順便說一句,感謝所有的重播,即時通訊仍然在做一些閱讀php.net,測試,並嘗試。
'SCRIPT_FILENAME' => string 'D:/Project Storage/wnmp/www/folder/index.php' (length=45)
'SCRIPT_NAME' => string '/folder/folder2/index.php' (length=18)
'DOCUMENT_URI' => string '/folder/folder2/index.php' (length=18)
'PHP_SELF' => string '/folder/folder2/index.php' (length=18)
'REQUEST_URI' => string '/folder/folder2/helloworld/helloworldtwo/etc' (length=15)
的問題還是一樣的我怎樣才能將HelloWorld/hellowrodltwo /等的正確途徑。
編輯* 謝謝你們了很多我做了一個解決方案
$str = 'folder/folder/helloworld/helloworldtwo/etc';
$folder = 'folder/folder';
$q = str_replace($folder, NULL, $str);
echo $q;
,但如果有什麼/替代或更好的方式來做到這一點,請做。
再次感謝。
你看過[parse_url](http://php.net/manual/en/function.parse-url.php)和[pathinfo](http:// uk3。 php.net/manual/en/function.pathinfo.php) - 和它們相關的函數(如基本名稱等)? – Mike 2010-12-07 13:27:43