2011-11-21 65 views
1

我有一個網址,http://members.exampledomain.com,我只想在我的頁面上顯示exampledomain。剝離出的 'http://成員' 和 '.com' 之間只顯示URL地址域

例如http://members.exampledomain.com的索引頁面有類似

<img src="members/images/logo<?=$exampledomain; ?>.png" /> 

確定這工作:

<?php 
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; 

$ArrayOfStrings = explode(".", $url); 

echo $ArrayOfStrings[1]; 
include("variables/" . $ArrayOfStrings[1] . "/config.inc"); 
?> 
+0

你已經有了正確的功能作爲標籤,有什麼難度? – deviousdodo

+0

我使用這個腳本,但它的打印成員,而不是exampledomain – Hector

+0

'code' <?php function URLVariable(){ $ url ='http'; if($ _SERVER [「HTTPS」] ==「on」){$ url。=「s」;} $ url。=「://」;如果($ _SERVER [「SERVER_PORT」]!=「80」){ $ url。= $ _SERVER [「SERVER_NAME」]。「:」。$ _ SERVER [「SERVER_PORT」]。$ _ SERVER [「REQUEST_URI」]; } else { $ url。= $ _SERVER [「SERVER_NAME」]。$ _ SERVER [「REQUEST_URI」]; } $ urlarray = explode(「//」,$ url); $ subdomain = $ urlarray [1]; $ returnvalue = explode(「。」,$ subdomain); return $ returnvalue [0]; } ?> <? $ urlvar = URLVariable(); ?> <?= $ urlvar; ''code' – Hector

回答

0

您包括了爆炸標籤。我假設你正在尋找使用爆炸功能的幫助?

<?php 
$url = "http://memebers.exampledomain.com"; 

$ArrayOfStrings = explode(".", $url); 

echo $ArrayOfStrings[1]; 
?> 
0

我註釋了此代碼以使其可讀。下次做一些研究:

<?php 

$url = "http://members.exampledomain.com/"; 
$url_parsed = parse_url($url); 
$host = $url_parsed["host"]; 
$host_exploded = explode(".", $host); 

echo $host_exploded[count($host_exploded) - 2]; 

?> 
+0

這工作 'code' <?php $ url =「http://」。$ _ SERVER ['HTTP_HOST']。$ _ SERVER ['SCRIPT_NAME']; $ ArrayOfStrings = explode(「。」,$ url); echo $ ArrayOfStrings [1];包括(「variables /」。$ ArrayOfStrings [1]。「/config.inc」); ?> 'code' – Hector

+0

如果你有這個網址會發生什麼:'http://asdexample.com/index.php?foo=.bar';) – Blender

+0

我係統上的所有域都有相同的子域http: //成員。唯一會改變的是主要領域 – Hector