$url = "http://google.com/xxx.html?xxx=xxx"; preg_match('@^(?:http://)?([^/]+)@i', $url, $matches); $host = $matches[1]; echo $host;