2
這裏是我的代碼:
$url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$urlcomplete = $url;
$url = explode(".com/",$url);
$urlcount = count($url);
$newurl = '';
for ($start = 1; $start < $urlcount; $start++) {
if ($newurl != '') {
$newurl .= '.com/';
}
$newurl .= $url[$start];
}
$url = explode('/',$newurl);
$urlcount = explode('?',end($url));
$url[count($url) - 1] = $urlcount[0];
$urlcount = count($url);
通過使用上面的代碼,所有的子頁面會店在$ url中。
https://stackoverflow.com/questions/ask
$url[0] = 'questions'
$url[1] = 'ask'
只想問一句,這是很好的方式,或者還有其他更好的辦法?
你需要一個正則表達式。當你有一個非'.com'域時會發生什麼? – Kermit
你試圖在人力方面完成什麼? –
從http://stackoverflow.com/questions/ask獲得什麼url的部分是你想要獲得的。 –