我需要从字符串中提取域名,这可能是任何东西.如:
$sitelink="http://www.somewebsite.com/product/3749875/info/overview.html";
要么
$sitelink="http://subdomain.somewebsite.com/blah/blah/whatever.PHP";
在任何情况下,我都想提取’somewebsite.com’部分(可能是任何东西),并丢弃其余部分.
随着
parse_url($url)
原文链接:https://www.f2er.com/php/137594.html<?PHP $url = 'http://username:password@hostname/path?arg=value#anchor'; print_r(parse_url($url)); ?> The above example will output: Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor )
使用thos值
echo parse_url($url,PHP_URL_HOST); //hostname
要么
$url_info = parse_url($url); echo $url_info['host'];//hostname