PluginProbe
Depicter — Popup & Slider Builder / 1.3.2
Depicter — Popup & Slider Builder v1.3.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / averta / core / src / Utility / Extract.php

Extract.php in Depicter — Popup & Slider Builder 1.3.2, at vendor/averta/core/src/Utility/Extract.php

61 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Averta\Core\Utility;
3
4
5 class Extract
6 {
7
8 /**
9 * Extracts domain from absolute url
10 *
11 * @param string $url
12 *
13 * @return mixed|string
14 */
15 public static function domain( $url ) {
16
17 if ( empty( $url ) ) {
18 return '';
19 }
20
21 $parsedUrl = parse_url( $url );
22
23 $host = '';
24
25 if( isset( $parsedUrl['host'] ) ){
26 $host = $parsedUrl['host'];
27
28 // if it was a plain url without schema
29 } elseif( isset( $parsedUrl['path'] ) ){
30 $host = $parsedUrl['path'];
31 }
32
33 $hostParts = explode(".", $host);
34 $domainExtensions = [];
35
36 if( count( $hostParts ) > 2 ){
37 $domainExtensions = array_slice( $hostParts, -2 );
38 }
39
40 if( count( $hostParts ) === 3 ){
41 if( strlen( implode( '', $domainExtensions ) ) > 5 ){
42 $hostParts = $domainExtensions;
43 }
44
45 } elseif( count( $hostParts ) > 3 ){
46 // skip ips
47 if( ! is_numeric( implode( '', $hostParts ) ) ){
48 // if one of the last two parts is domain
49 if( strlen( implode( '', $domainExtensions ) ) > 5 ){
50 $hostParts = $domainExtensions;
51 } else {
52 $hostParts = array_slice( $hostParts, -3 );
53 }
54 }
55 }
56
57 $host = implode( '.', $hostParts );
58 return trim( $host, '/' );
59 }
60 }
61