I think that мппм.рф
is already in UTF8, so forcing a conversion will not help. Your regular expression is quite simple, and can be replace by something like this:
function validateDomain($domain)
{
$parts = explode('.',$domain);
$name = array_shift($parts);
$extension = implode('.',$parts);
if ((strlen($name) >= 2) && (strlen($name) <= 100) &&
(strlen($extension) >= 2) && (strlen($extension) <= 24)) return $domain;
else return FALSE;
}
It will work the same, but also for non-a-z characters, and it is easier to understand than when it uses a regular expression. You can make it slightly more compact and efficient by doing this:
function validateDomain($domain)
{
$parts = explode('.',$domain);
$nameLen = strlen(array_shift($parts));
$extLen = strlen(implode('.',$parts));
if( ($nameLen >= 2) && ($nameLen <= 100) &&
($extLen >= 2) && ($extLen <= 24) ) return $domain;
else return FALSE;
}
You could also use the multibyte string functions like this:
function validateDomain($domain)
{
$point = mb_strpos($domain,'.');
$nameLen = mb_strlen(mb_substr($domain,0,$point));
$extLen = mb_strlen(mb_substr($domain,$point+1));
if( ($nameLen >= 2) && ($nameLen <= 100) &&
($extLen >= 2) && ($extLen <= 24) ) return $domain;
else return FALSE;
}