function isDigits(string $s, int $minDigits = 9, int $maxDigits = 14): bool {
return preg_match('/^[0-9]{'.$minDigits.','.$maxDigits.'}\z/', $s);
}
function isValidTelephoneNumber(string $telephone, int $minDigits = 9, int $maxDigits = 14): bool {
if (preg_match('/^[+][0-9]/', $telephone)) {
$count = 1;
$telephone = str_replace(['+'], '', $telephone, $count);
}
$telephone = str_replace([' ', '.', '-', '(', ')'], '', $telephone);
return $this->isDigits($telephone, $minDigits, $maxDigits);
}
function normalizeTelephoneNumber(string $telephone): string {
$telephone = str_replace([' ', '.', '-', '(', ')'], '', $telephone);
return $telephone;
}
$tel = '+9112 345 6789';
if (isValidTelephoneNumber($tel)) {
echo normalizeTelephoneNumber($tel);
}