@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Url |
| 5 | 5 | */ |
| 6 | -class UrlTool{ |
|
| 6 | +class UrlTool { |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * 获取url中主域名 |
@@ -11,16 +11,16 @@ discard block |
||
| 11 | 11 | * @return string |
| 12 | 12 | */ |
| 13 | 13 | function getMainDomain($url) { |
| 14 | - $url = strtolower($url);//首先转成小写 |
|
| 14 | + $url = strtolower($url); //首先转成小写 |
|
| 15 | 15 | $host = parse_url($url, PHP_URL_HOST); // 获取host部分 |
| 16 | - if(empty($host)){ |
|
| 16 | + if (empty($host)) { |
|
| 17 | 17 | $url = "https://".$url; |
| 18 | - $host = parse_url($url,PHP_URL_HOST); |
|
| 18 | + $host = parse_url($url, PHP_URL_HOST); |
|
| 19 | 19 | } |
| 20 | 20 | if (!$host) { |
| 21 | 21 | return ''; |
| 22 | 22 | } |
| 23 | - if (in_array($host,['127.0.0.1','localhost'])) { |
|
| 23 | + if (in_array($host, ['127.0.0.1', 'localhost'])) { |
|
| 24 | 24 | return ''; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | * 判断是否是双后缀aaa.com.cn |
| 35 | 35 | */ |
| 36 | 36 | $preg = '/[\w].+\.(com|net|org|gov|edu)\.cn$/'; |
| 37 | - if ($count > 2 && preg_match($preg,$host)){ |
|
| 37 | + if ($count > 2 && preg_match($preg, $host)) { |
|
| 38 | 38 | //双后缀取后3位 |
| 39 | - $host = $parts[$count-3].'.'.$parts[$count-2].'.'.$parts[$count-1]; |
|
| 40 | - } else{ |
|
| 39 | + $host = $parts[$count - 3].'.'.$parts[$count - 2].'.'.$parts[$count - 1]; |
|
| 40 | + } else { |
|
| 41 | 41 | // 如果只有两个部分,则直接返回整个host作为主域名 |
| 42 | - $host = $parts[$count-2].'.'.$parts[$count-1]; |
|
| 42 | + $host = $parts[$count - 2].'.'.$parts[$count - 1]; |
|
| 43 | 43 | } |
| 44 | 44 | return $host; |
| 45 | 45 | } |