ePages 6.11.0 - DE_EPAGES/Core/API/IDN.pm

Package DE_EPAGES::Core::API::IDN

This Module provides some function for international domain names (IDN).

@EXPORT_OK
AreDomainsEqual
DecodeDomain
DecodeDomainInEMailAddress
DecodeDomainInUrl
EncodeDomain
EncodeDomainInEMailAddress
EncodeDomainInUrl
IsValidIDN

Functions

AreDomainsEqual
DecodeDomain
DecodeDomainInEMailAddress
DecodeDomainInUrl
EncodeDomain
EncodeDomainInEMailAddress
EncodeDomainInUrl
IsValidIDN

AreDomainsEqual

Check if two domains are equal; every combination of ACE, IDN, uppercase and lowercase domain names are allowed. If one domain is undef the function returns true if and only if the other one is undef, too. Otherwise, the domains will be converted to their ACE representation if necessary (e.g. www.müller.de => www.xn--mller-kva.de), all characters converted to lowercase, and the results will be compared. Examples: AreDomainsEqual('wWW.MÜLLerØ.de', 'www.xn--mller-ipax.DE') == 1 AreDomainsEqual('www.TestIdeen.de', 'www.testideen.de') == 1

Syntax
$Equal = AreDomainsEqual($domain1, $domain2)
if(!AreDomainsEqual($domain1, $domain2)) {...
Input
$domain1 (string)
domain
$domain2 (string)
domain to compare with
Return
$Equal (boolean)
true if the 2 domain names are equivalent

DecodeDomain

decode a domain name from the IDN representation to a readable one. Examples: DecodeDomain('xn--mller-kva.de') eq 'müller.de' DecodeDomain('xn--ss-uia6e4a.de') eq 'äöüß.de' DecodeDomain('xn--srensen-q1a.dk') eq 'sørensen.dk' DecodeDomain('xn--bcher-kva.xn--mller-kva.de') eq 'bücher.müller.de' DecodeDomain('wasser.de') eq 'wasser.de'

Syntax
$DecodedDomain = DecodeDomain( $EncodedDomain );
Example
$DecodedDomain = DecodeDomain( 'xn--mller-kva.de' );
Input
$EncodedDomain (string)
domain name; may or may not contain a toplevel domain
Return
$DecodedDomain (string)
the domain containing special chars, if any had been encoded

DecodeDomainInEMailAddress

decode the email adress's domain name with DecodeDomain();

Syntax
$DecodedEmail = DecodeDomainInEMailAddress( $EncodedEmail );
Example
$DecodedEmail = DecodeDomainInEMailAddress( 'max@xn--mller-kva.de' );
Input
$EncodedEmail (string)
the email address
Return
$DecodedEmail (string)
the email address with decoded domain

DecodeDomainInUrl

decode a domain name using DecodeDomain() in a url. Example: DecodeDomainInUrl('http://www.xn--mller-kva.de/index.html') eq 'http://www.müller.de/index.html' if the input is not a correct url the function throws the error 'FORMAT_NOT_URL'

Syntax
$DecodedUrl = DecodeDomainInUrl($EncodedUrl);
Example
$DecodedUrl = DecodeDomainInUrl('http://www.xn--mller-kva.de/index.html');
Input
$EncodedUrl (string)
the url beginning with the protocol
Return
$DecodedUrl (string)
url with server name decoded with DecodeDomain()

EncodeDomain

encode a domain name for use in IDN applications; if the domain does only contain ascii chars 33 to 127 it will be returned unchanged except that all letters will be lowercase and ß will be replaced by ss; otherwise the punycode presentation will be returned. Examples: EncodeDomain('müller.de') eq 'xn--mller-kva.de' EncodeDomain('MÜLLER.de') eq 'xn--mller-kva.de' EncodeDomain('MuELlEr.de') eq 'mueller.de' EncodeDomain('äöüß.de') eq 'xn--ss-uia6e4a.de' EncodeDomain('Sørensen.dk') eq 'xn--srensen-q1a.dk' EncodeDomain('BÜcher.müLLEr.de') eq 'xn--bcher-kva.xn--mller-kva.de' EncodeDomain('waßER.de') eq 'wasser.de'

Syntax
$EncodedDomain = EncodeDomain( $DecodedDomain );
Example
$EncodedDomain = EncodeDomain( 'müller.de' );
Input
$DecodedDomain (string)
domain name; may or may not contain a toplevel domain
Return
$EncodedDomain (string)
the domain for use in IDN applications; contains the top level domain
of the input, if any

EncodeDomainInEMailAddress

encode the email adress's domain name with EncodeDomain();

Syntax
$EncodedEmail = EncodeDomainInEMailAddress( $DecodedEmail );
Example
$EncodedEmail = EncodeDomainInEMailAddress( 'max@müller.de' );
Input
$DecodedEmail (string)
the email address
Return
$EncodedEmail (string)
the email address with encoded domain

EncodeDomainInUrl

encode a domain name using EncodeDomain() in a url. Example: EncodeDomainInUrl('http://www.müller.de/index.html') eq 'http://www.xn--mller-kva.de/index.html' if the input is not a correct url the function throws the error 'FORMAT_NOT_URL'

Syntax
$EncodedUrl = EncodeDomainInUrl($DecodedUrl);
Example
$EncodedUrl = EncodeDomainInUrl('http://www.müller.de/index.html');
Input
$DecodedUrl (string)
the url beginning with the protocol
Return
$EncodedUrl (string)
url with server name encoded with EncodeDomain()

IsValidIDN

checks if the input is a syntactically valid international domain name

Syntax
$OK = IsValidIDN($Domain);
Example
if (!CheckDomainName('www.müller.de')) {...
Input
$Domain (string)
the domain name to check
Return
$OK (string)
true if the domain name is valid