PHP URL 解析 &解剖 [英] PHP URL Parsing & disecting

查看:22
本文介绍了PHP URL 解析 &解剖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • www.example.com
  • foo.example.com
  • foo.example.co.uk
  • foo.bar.example.com
  • foo.bar.example.co.uk

我在这里有这些 URL,并且希望始终以 2 个变量结束:

I've got these URL's here, and want to always end up with 2 variables:

$domainName = "example"
$domainNameSuffix = ".com" OR ".co.uk"

如果有人能让我从 $url 成为网址之一,一直到 $newUrl 接近example.co.uk",那将是一种祝福.

If I someone could get me from $url being one of the urls, all the way down to $newUrl being close to "example.co.uk", it would be a blessing.

请注意,网址将完全是随机的",我们最终也可能会拥有foo.bar.example2.com.au",所以……您知道……呃.(要求不可能的事?)

Note that the urls are going to be completely "random", we might end up having "foo.bar.example2.com.au" too, so ... you know... ugh. (asking for the impossible?)

干杯,

推荐答案

domainNameSuffix"被称为 顶级域(简称tld),并且没有简单的方法来提取它.

The "domainNameSuffix" is called a top level domain (tld for short), and there is no easy way to extract it.

每个国家/地区都有自己的 tld,有些国家/地区选择进一步细分其 tld.而且由于子域的数量 (my.own.subdomain.example.com) 也是可变的,因此没有简单的one-regexp-fits-all".

Every country has it's own tld, and some countries have opted to further subdivide their tld. And since the number of subdomains (my.own.subdomain.example.com) is also variable, there is no easy "one-regexp-fits-all".

如前所述,您需要一个列表.幸运的是,有一些公开可用的列表:http://publicsuffix.org/

As mentioned, you need a list. Fortunately for you there are lists publicly available: http://publicsuffix.org/

这篇关于PHP URL 解析 &解剖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆