你可以使用 PHP 的字符串处理函数来去掉域名的后缀。例如,使用 `pathinfo()` 或者正则表达式。
使用 `pathinfo()`:
php
$url = 'http://example.com';
$domain = parse_url($url, PHP_URL_HOST);
$domainWithoutSuffix = pathinfo($domain, PATHINFO_FILENAME);
echo $domainWithoutSuffix; // 输出 'example'
使用正则表达式:
php
$url = 'http://example.com';
$domain = parse_url($url, PHP_URL_HOST);
$domainWithoutSuffix = preg_replace('/\.[^.]+$/', '', $domain);
echo $domainWithoutSuffix; // 输出 'example'
这两种方法都能帮你去掉域名的后缀。根据具体需求选择合适的方法。
查看详情
查看详情