original_string: public static function is_domain_name($domainname) {
          if (!is_string($domainname)) {
              return false;
          }
          // Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal.
          $domainname = rtrim($domainname, '.');
  
          // The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte).
          if (strlen($domainname) > 253) {
              return false;
          }
          // Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen.
          // The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked).
          $domaintertiary = '([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\.)*';
          $domaintoplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)';
          $address = '(' . $domaintertiary .  $domaintoplevel . ')';
          $regexp = '#^' . $address . '$#i'; // Case insensitive matching.
          return preg_match($regexp, $domainname, $match) == true; // False for error, 0 for no match - we treat the same.
      }
code: public static function is_domain_name($domainname) {
          if (!is_string($domainname)) {
              return false;
          }
          // Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal.
          $domainname = rtrim($domainname, '.');
  
          // The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte).
          if (strlen($domainname) > 253) {
              return false;
          }
          // Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen.
          // The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked).
          $domaintertiary = '([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\.)*';
          $domaintoplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)';
          $address = '(' . $domaintertiary .  $domaintoplevel . ')';
          $regexp = '#^' . $address . '$#i'; // Case insensitive matching.
          return preg_match($regexp, $domainname, $match) == true; // False for error, 0 for no match - we treat the same.
      }
code_tokens: public static function is_domain_name ( $ domainname ) { if ( ! is_string ( $ domainname ) ) { return false ; } // Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal. $ domainname = rtrim ( $ domainname , '.' ) ; // The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte). if ( strlen ( $ domainname ) > 253 ) { return false ; } // Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen. // The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked). $ domaintertiary = '([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\.)*' ; $ domaintoplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)' ; $ address = '(' . $ domaintertiary . $ domaintoplevel . ')' ; $ regexp = '#^' . $ address . '$#i' ; // Case insensitive matching. return preg_match ( $ regexp , $ domainname , $ match ) == true ; // False for error, 0 for no match - we treat the same. }
docstring: Syntax checking for domain names, including fully qualified domain names.
  
  This function does not verify the existence of the domain name. It only verifies syntactic correctness.
  This is based on RFC1034/1035 and does not provide support for validation of internationalised domain names (IDNs).
  All IDNs must be prior-converted to their ascii-compatible encoding before being passed to this function.
  
  @param string $domainname the input string to check.
  @return bool true if the string has valid syntax, false otherwise.
docstring_tokens: Syntax checking for domain names including fully qualified domain names .