<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ##域名操作工具類 ~~~ class domainTool { static $suffix = array( 'org.cn', 'gov.cn', 'com.cn', 'net.cn' ); /** * 獲取域名后綴 * @param string $url 域名地址 * http://www.domain.com.cn 返回 com.cn * @return string */ static function getSuffix($url) { $parseUrl = parse_url($url); $domain = isset($parseUrl['host']) ? $parseUrl['host'] : $parseUrl['path']; //通過 . 分隔域名 $pieces = explode(".", $domain); if(empty($pieces)){ return ''; } //域名后綴下標 $index = count($pieces) - 1; //嘗試獲取com.cn, net.cn等后綴 $prevIndex = $index - 1; $suffix = $pieces[$prevIndex] . '.' . $pieces[$index]; //如果為com.cn, net.cn等后綴,直接返回 if (in_array($suffix, self::$suffix)) { return $suffix; } else { return $pieces[$index]; //直接返回域名后綴下標 } } /** * 獲取根域名 * @example * http://aaa.bbb.ccc.domain.net.cn:9000/xxx/yyy?zzz=1 默認返回 domain.net.cn:9000 * @param string $url 域名地址 * @param string $subDomain 返回的二級域名 * @param bool $needPort 是否帶上端口號 * @return string */ static function getRoot($url = '', $subDomain = '', $needPort = true) { if (empty($url)) { $url = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']; } //解析域名地址 $parseUrl = parse_url($url); if (!isset($parseUrl['host']) || empty($url)) { return ''; } else { $domain = $parseUrl['host']; } //如果為ip,則直接返回 if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $domain)){ return $domain; } //判斷是否為com.cn、net.cn等域名后綴 $suffix = self::getSuffix($domain); $pieces = explode('.', $domain); if (strpos($suffix, '.') !== false) { $index = count($pieces) - 3; } else { $index = count($pieces) - 2; } $name = $pieces[$index]; $rootDomain = ($subDomain ? $subDomain . '.' : '') . $name . '.' . $suffix; return $rootDomain . ($needPort && isset($parseUrl['port']) ? ':' . $parseUrl['port'] : ''); } } ~~~ ##示例 ~~~ $url = 'http://aaa.bbb.ccc.domain.net.cn:9000/xxx/yyy?zzz=1'; /* * ------- 獲取域名后綴示例 */ //輸出net.cn echo domainTool::getSuffix($url); /* * ------- 獲取根域名示例 */ //輸出domain.net.cn:9000 echo domainTool::getRoot($url); //輸出sub.domain.net.cn:9000 echo domainTool::getRoot($url,'sub'); //輸出www.domain.net.cn echo domainTool::getRoot($url,'www',false); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看