fork download
  1. <?php
  2.  
  3. // Правильные:
  4. $correctNumbers = [
  5. '84951234567',
  6. '+74951234567',
  7. '8-495-1-234-567',
  8. ' 8 (8122) 56-56-56',
  9. '8-911-1234567',
  10. '8 (911) 12 345 67',
  11. '8-911 12 345 67',
  12. '8 (911) - 123 - 45 - 67',
  13. '+ 7 999 123 4567',
  14. '8 ( 999 ) 1234567',
  15. '8 999 123 4567'
  16. ];
  17.  
  18. $results = preg_replace(['/[\s()-]/', '/^\+\s?7/'], ['', '8'], $correctNumbers);
  19. print_r($results);
  20.  
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 84951234567
    [1] => 84951234567
    [2] => 84951234567
    [3] => 88122565656
    [4] => 89111234567
    [5] => 89111234567
    [6] => 89111234567
    [7] => 89111234567
    [8] => 89991234567
    [9] => 89991234567
    [10] => 89991234567
)