php – 根据公共后缀列表从URL中提取注册域
发布时间:2020-12-13 17:29:42 所属栏目:PHP教程 来源:网络整理
导读:给定URL,如何使用 Public Suffix List(有效TLD列表,例如 this list)提取注册域? 例如,考虑a.bg是一个有效的公共后缀: http://www.test.start.a.bg/hello.html - start.a.bg http://test.start.a.bg/ - start.a.bghttp://test.start.abc.bg/ - abc.bg (.bg
给定URL,如何使用
Public Suffix List(有效TLD列表,例如
this list)提取注册域?
例如,考虑a.bg是一个有效的公共后缀: http://www.test.start.a.bg/hello.html -> start.a.bg http://test.start.a.bg/ -> start.a.bg http://test.start.abc.bg/ -> abc.bg (.bg is the public suffix) 这不能使用简单的字符串操作来完成,因为根据TLD,公共后缀可以由多个级别组成. 附:读取列表(数据库或平面文件)并不重要,但列表应该在本地可访问,因此我并不总是依赖于外部服务.
您可以使用parse_url()提取主机名,然后使用
library provided by regdom来确定注册的域名(dn eTLD).例如:
require_once("effectiveTLDs.inc.php"); require_once("regDomain.inc.php"); $url = 'http://www.metu.edu.tr/dhasjkdas/sadsdds/sdda/sdads.html'; echo getRegisteredDomain(parse_url($url,PHP_URL_HOST)); 这将打印出metu.edu.tr. 我试过的其他例子 http://www.xyz.start.bg/hello -> start.bg http://www.start.a.bg/world -> start.a.bg (a.bg is a listed eTLD) http://xyz.ma219.metu.edu.tr -> metu.edu.tr http://www.google.com/search -> google.com http://google.co.uk/search?asd -> google.co.uk 更新:这些库已被移动到:https://github.com/leth/registered-domains-php (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |