code: public static function normalizeOpenId($identifier)
      {
          // XRI
          if (preg_match('@^xri://@i', $identifier)) {
              return preg_replace('@^xri://@i', '', $identifier);
          }
  
          if (in_array($identifier[0], array('=', '@', '+', '$', '!'))) {
              return $identifier;
          }
  
          // URL
          if (!preg_match('@^http[s]?://@i', $identifier)) {
              $identifier = 'http://' . $identifier;
          }
          if (strpos($identifier, '/', 8) === false) {
              $identifier .= '/';
          }
          if (!filter_var($identifier, FILTER_VALIDATE_URL)) {
              return '';
          }
  
          $parts = parse_url($identifier);
          $parts['scheme'] = strtolower($parts['scheme']);
          $parts['host']   = strtolower($parts['host']);
  
          //http://openid.net/specs/openid-authentication-2_0.html#normalization
          return $parts['scheme'] . '://'
              . (isset($parts['user']) ? $parts['user'] : '')
              . (isset($parts['pass']) ? ':' . $parts['pass'] : '')
              . (isset($parts['user']) || isset($parts['pass']) ? '@' : '')
              . $parts['host']
              . (
                  (isset($parts['port'])
                  && $parts['scheme'] === 'http' && $parts['port'] != 80)
                  || (isset($parts['port'])
                  && $parts['scheme'] === 'https' && $parts['port'] != 443)
                  ? ':' . $parts['port'] : ''
              )
              . $parts['path']
              . (isset($parts['query']) ? '?' . $parts['query'] : '');
              //leave out fragment as requested by the spec
      }
docs: Normalizes an identifier (URI or XRI)
  
  @param mixed $identifier URI or XRI to be normalized
  
  @return string Normalized Identifier.
  Empty string when the OpenID is invalid.
  
  @internal Adapted from OpenID::normalizeIdentifier()