ain is valid or not. */ private function isValidDomain( $domain ) { // In case there are unicode characters, convert it into // IDNA ASCII URLs if ( function_exists( 'idn_to_ascii' ) ) { $domain = idn_to_ascii( $domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46 ); } if ( ! $domain ) { return false; } $domain = preg_replace( '/^\*\.+/', '', $domain ); return preg_match( '/^(?!\-)(?:[a-z\d\-]{0,62}[a-z\d]\.){1,126}(?!\d+)[a-z\d]{1,63}$/i', $domain ); } /** * Returns a single string of all subdomains associated with this domain. * Example 1: www * Example 2: ww2.www * * @since 4.5.9 * * @return array The subdomains associated with this domain. */ public function getSubdomains( $domain ) { // If we can't find a TLD, we won't be able to parse a subdomain. if ( empty( $this->getTld( $domain ) ) ) { return []; } // Return any subdomains as an array. return array_filter( explode( '.', rtrim( strstr( $domain, $this->getTld( $domain ), true ), '.' ) ) ); } /** * Returns the TLD associated with the given domain. * * @since 4.5.9 * * @param string $domain The domain. * @return string The TLD. */ public function getTld( $domain ) { if ( preg_match( '/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $matches ) ) { return $matches['tld']; } return $domain; } }