获取域名主域名API
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
$url = $_GET['url'] ?? '';
if (!$url) {
exit(json_encode(['code' => '110', 'message' => '参数不完整'], JSON_UNESCAPED_UNICODE));
}
$mainDomain = getMainDomain($url);
echo $mainDomain;
function getMainDomain($url) {
$parsedUrl = parse_url($url);
$host = $parsedUrl['host'] ?? '';
$suffixList = [
'.中国', '.公司', '.网络', '.网址', '.商城', '.网店', '.中信', '.商标', '.广东', '.佛山', '.信息', '.手机', '.在线', '.中文网', '.集团', '.我爱你', '.商店',
'.企业', '.娱乐', '.游戏', '.购物', '.餐厅', '.招聘', '.时尚', '.移动', '.网站', '.联通', '.世界', '.健康', '.ren', '.wang', '.citic', '.top', '.sohu',
'.xin', '.com', '.net', '.club', '.xyz', '.vip', '.site', '.shop', '.ink', '.info', '.mobi', '.red', '.pro', '.kim', '.ltd', '.group', '.biz',
'.auto', '.link', '.work', '.law', '.beer', '.store', '.tech', '.fun', '.online', '.art', '.design', '.wiki', '.love', '.center', '.video',
'.social', '.team', '.show', '.cool', '.zone', '.world', '.today', '.city', '.chat', '.company', '.live', '.fund', '.gold', '.plus', '.guru',
'.run', '.pub', '.email', '.life', '.co', '.fashion', '.fit', '.luxe', '.yoga', '.baidu', '.cloud', '.host', '.space', '.press', '.website',
'.archi', '.asia', '.bio', '.black', '.blue', '.green', '.lotto', '.organic', '.pet', '.pink', '.poker', '.promo', '.ski', '.vote', '.voto',
'.icu', '.fans', '.unicom', '.jpmorgan', '.chase', '.cc', '.tv', '.band', '.cab', '.cafe', '.cash', '.fan', '.fyi', '.games', '.market', '.mba',
'.news', '.media', '.sale', '.shopping', '.studio', '.tax', '.technology', '.vin', '.baby', '.college', '.monster', '.protection', '.rent',
'.security', '.storage', '.theatre', '.bond', '.cyou', '.uno', '.school', '.global', '.me', '.pw', '.cn', '.政务.cn', '.公益.cn', '.gov.cn',
'.org.cn', '.ac.cn', '.mil.cn', '.net.cn', '.edu.cn', '.com.cn', '.bj.cn', '.tj.cn', '.sh.cn', '.cq.cn', '.he.cn', '.sx.cn', '.nm.cn', '.ln.cn',
'.jl.cn', '.hl.cn', '.js.cn', '.zj.cn', '.ah.cn', '.fj.cn', '.jx.cn', '.sd.cn', '.ha.cn', '.hb.cn', '.hn.cn', '.gd.cn', '.gx.cn', '.hi.cn',
'.sc.cn', '.gz.cn', '.yn.cn', '.xz.cn', '.sn.cn', '.gs.cn', '.qh.cn', '.nx.cn', '.xj.cn', '.tw.cn', '.hk.cn', '.mo.cn'
];
$suffix = '';
foreach ($suffixList as $suf) {
if (substr($host, -strlen($suf)) == $suf) {
$suffix = $suf;
break;
}
}
if ($suffix) {
$arr = explode($suffix, $host);
$mainDomain = end($arr) . $suffix;
return $mainDomain;
} else {
return $host;
}
}
使用方法:
https://your-domain.com/api?url=https://www.example.com/path/to/page
返回结果:
{
'code': 200,
'message': 'success',
'data': 'example.com'
}
原文地址: https://www.cveoy.top/t/topic/lJFU 著作权归作者所有。请勿转载和采集!