Possible Duplicate:
Parsing Domain From URL In PHP
how do i get
http://localhost/
from
http://localhost/something/
using php
I tried
$base = strtok($url, '/');
You can use parse_url to get down to the hostname.
e.g.:
$url = "http://localhost/path/to/?here=there";
$data = parse_url($url);
var_dump($data);
/*
Array
(
[scheme] => http
[host] => localhost
[path] => /path/to/
[query] => here=there
)
*/
$url = 'http://localhost/something/';
$parsedurl = parse_url($url);
echo $parsedurl['scheme'].'://'.$parsedurl['host'];
Check out parse_url()
- http://php.net/parse_url
精彩评论