2010-05-09 36 views
0

當前網址的示例http://www.domain.com/subdomain/install/finish.php如何使用php過濾當前網址

我使用此代碼獲取當前網址。

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; 

現在我想要得到的URL看起來像http://www.domain.com/subdomain如果沒有子文件夾,它會讀取像http://www.domain.com

讓我知道。

+0

URL定義可以簡化爲:'$ URL =((空($ _ SERVER [ 'HTTPS']))「的https:// 「:」http://「)。 $ _SERVER ['SERVER_NAME']。$ _ SERVER ['REQUEST_URI'];' – Yahel 2011-08-08 19:24:17

回答

3

我不是很瞭解您的要求,但看看parse_url()

它分割一個URL分爲以下幾個片段:

* scheme - http:// 
* host www.domain.com 
* port 
* user 
* pass 
* path /subdomain/install/finish.php 
* query 
* fragment 
+0

我希望我可以upvote這個,但我今天沒有更多的選票:(好的答案! – 2010-05-09 07:28:33