Skip to content

Instantly share code, notes, and snippets.

@Pahom-ka
Created February 15, 2024 07:06
Show Gist options
  • Save Pahom-ka/cb5d280c1ec1bcf346c8c7afceda4066 to your computer and use it in GitHub Desktop.
Save Pahom-ka/cb5d280c1ec1bcf346c8c7afceda4066 to your computer and use it in GitHub Desktop.
modx visual number format
<?php
$number = $input;
$number = preg_replace('/[^0-9]/', '', $number); // удаление всех символов, кроме цифр
if (strlen($number) === 11) { // номер с кодом страны
$formattedNumber = preg_replace('/(\d{1})(\d{3})(\d{3})(\d{2})(\d{2})/', '8 ($2) $3-$4-$5', $number);
} elseif (strlen($number) === 10) { // номер без кода страны
$formattedNumber = preg_replace('/(\d{3})(\d{3})(\d{2})(\d{2})/', '8 ($1) $2-$3-$4', $number);
}
return $formattedNumber;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment