2013-02-09 38 views
-1

我有一個問題,我使用dirname($_SERVER['PHP_SELF']);獲得當前頁面的網址,我結束了這/clients/sherloc_media/install和即時嘗試使用explode()得到這個/clients/sherloc_media我需要這個1個變量,然後我需要sherloc_media另外,我一直在嘗試這在過去的幾個小時的/clients/sherloc_media我自己就要被使用爲$root變量,PHP:爆炸的第3個字符

不知何故,我已經結束了,像這樣http://localhost/clients/sherloc_media/operate/opertate/index.php

鏈接

當它被認爲是http://localhost/clients/sherloc_media/opertate/index.php

任何幫助將是巨大的感謝,我沒有說香港專業教育學院使用得到的錯誤結果,因爲我已經刪除並重新開始,你知道破解任何代碼,歡呼聲

回答

1

一個的方法很多:

$firstPart = substr(rtrim($path, '/'), 0, strrpos($path, '/')); 

或者如果你喜歡爆炸:

$parts = explode('/', trim($path, '/')); 
$firstPart = $parts[0] . '/' . $parts[1]; 
+0

謝謝:)很大的幫助 – iConnor 2013-02-09 00:42:57