<i id='bml6q'><tr id='bml6q'><dt id='bml6q'><q id='bml6q'><span id='bml6q'><b id='bml6q'><form id='bml6q'><ins id='bml6q'></ins><ul id='bml6q'></ul><sub id='bml6q'></sub></form><legend id='bml6q'></legend><bdo id='bml6q'><pre id='bml6q'><center id='bml6q'></center></pre></bdo></b><th id='bml6q'></th></span></q></dt></tr></i><div id='bml6q'><tfoot id='bml6q'></tfoot><dl id='bml6q'><fieldset id='bml6q'></fieldset></dl></div>
    1. <tfoot id='bml6q'></tfoot>
      • <bdo id='bml6q'></bdo><ul id='bml6q'></ul>

      <small id='bml6q'></small><noframes id='bml6q'>

      <legend id='bml6q'><style id='bml6q'><dir id='bml6q'><q id='bml6q'></q></dir></style></legend>

      从 url 中提取域(包括困难的域)

      时间:2023-09-23
        <tbody id='nVRUp'></tbody>

      • <bdo id='nVRUp'></bdo><ul id='nVRUp'></ul>

          <small id='nVRUp'></small><noframes id='nVRUp'>

        • <i id='nVRUp'><tr id='nVRUp'><dt id='nVRUp'><q id='nVRUp'><span id='nVRUp'><b id='nVRUp'><form id='nVRUp'><ins id='nVRUp'></ins><ul id='nVRUp'></ul><sub id='nVRUp'></sub></form><legend id='nVRUp'></legend><bdo id='nVRUp'><pre id='nVRUp'><center id='nVRUp'></center></pre></bdo></b><th id='nVRUp'></th></span></q></dt></tr></i><div id='nVRUp'><tfoot id='nVRUp'></tfoot><dl id='nVRUp'><fieldset id='nVRUp'></fieldset></dl></div>

            1. <legend id='nVRUp'><style id='nVRUp'><dir id='nVRUp'><q id='nVRUp'></q></dir></style></legend>

                <tfoot id='nVRUp'></tfoot>
                本文介绍了从 url 中提取域(包括困难的域)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试编写(或只是找到一个现有的)PHP 方法,该方法可以获取链接并提取 url.诀窍是,它需要承受像以下奇怪域的重量:

                I'm trying to write (or just find an existing) PHP method that can take a link and extract the url. The trick is, it needs to hold under the weight of strange looking domains like:

                www.champa.kku.ac.th 
                

                亲眼看到这个,我还是猜错了:原以为域名是kku.ac.th,但访问时出现dns错误.

                Looking at this one myself with human eyes, I still guessed it incorrectly: thought the domain would be kku.ac.th but that gives a dns error when visiting.

                所以任何人都知道从 url 中可靠地提取域的好方法:

                So anyone knows of a good way to reliably extract the domain from url:

                http://site.com/hello.php
                http://site.com.uk/hello.php
                http://subdomain.site.com/hello.php
                http://subdomain.site.com.uk/hello.php
                http://www.champa.kku.ac.th/hello.php // and even the one I couldn't tell
                

                推荐答案

                PHP 有 parse_url() 功能将帮助您进行基本的协议、主机、端口等拆分.

                PHP has the parse_url() function that will help you do the basic splitting into protocol, host, port, and so on.

                至于在不确定的情况下提取正确"的域,这很难说,因为有时两部分 TLD"是 TLD 当局(例如在英国)的措施,有时是私营企业(例如.uk.com).我认为您不会绕过维护包含两部分的顶级域列表,例如

                As to extracting the "right" domain in uncertain cases, this is extremely hard to tell because sometimes, "two-part TLDs" are a measure by the TLD authority (e.g. in the UK) and sometimes are private enterprises (e.g. .uk.com). I think you won't get around maintaining lists of top level domains that have two parts like

                • .co.uk
                • .ac.uk
                • .ac.th

                那些结尾将被视为 TLD(顶级 级别域),吞下第二部分.

                those endings would be treated like TLDs (Top level domains), swallowing the second part.

                这是可靠区分两部分 TLD"的唯一方法,例如 .co.uk - where server1.ibm.co.uk(其中两个-part .co.uk 需要从诸如 server1.ibm.com(其中 .com需要删除).

                This is the only way of reliably telling apart "two-part TLDs" like .co.uk - where server1.ibm.co.uk (where the two-part .co.uk needs to be removed to determine the domain itself) from regular sub-domains like server1.ibm.com (where .com needs to be removed).

                获取许多重要的两部分 TLD"列表的一个很好的起点是在 speednames.com 上进行域搜索(在国家/地区选择全部").更完整的列表可以在 Ruby domainatrix 库的一部分中找到.

                A good starting point to get a list of many important "two-part TLDs" is the domain search at speednames.com (select "all" in countries). A more complete list can be found as part of the Ruby domainatrix library.

                这篇关于从 url 中提取域(包括困难的域)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                1. <tfoot id='dB6G5'></tfoot>
                    <i id='dB6G5'><tr id='dB6G5'><dt id='dB6G5'><q id='dB6G5'><span id='dB6G5'><b id='dB6G5'><form id='dB6G5'><ins id='dB6G5'></ins><ul id='dB6G5'></ul><sub id='dB6G5'></sub></form><legend id='dB6G5'></legend><bdo id='dB6G5'><pre id='dB6G5'><center id='dB6G5'></center></pre></bdo></b><th id='dB6G5'></th></span></q></dt></tr></i><div id='dB6G5'><tfoot id='dB6G5'></tfoot><dl id='dB6G5'><fieldset id='dB6G5'></fieldset></dl></div>
                        <tbody id='dB6G5'></tbody>
                      <legend id='dB6G5'><style id='dB6G5'><dir id='dB6G5'><q id='dB6G5'></q></dir></style></legend>

                      • <bdo id='dB6G5'></bdo><ul id='dB6G5'></ul>
                      • <small id='dB6G5'></small><noframes id='dB6G5'>