fork download
  1. <?php
  2. $lines = array(
  3. '84951234567',
  4. '+74951234567',
  5. '8-495-1-234-567',
  6. '8 (8122) 56-56-56',
  7. ' 8-911-1234567',
  8. '8 (911) 12 345 67',
  9. '8-911 12 345 67',
  10. '8 (911) - 123 - 45 - 67',
  11. '+ 7 999 123 4567',
  12. '8 ( 909 ) 1234567',
  13. '8 999 123 4567',
  14. '8 952-58 -51 25-5',
  15. '02',
  16. '84951234567 позвать люсю',
  17. '849512345',
  18. '849512345678',
  19. '8 (409) 123-123-123',
  20. '7900123467',
  21. '5005005001',
  22. '8888-8888-88',
  23. '84951a234567',
  24. '8495123456a',
  25. '+1 234 5678901',
  26. '+8 234 5678901',
  27. '7 234 5678901'
  28. );
  29. $regexp_control = '/(^([- \\(\\)]*\\+[- \\(\\)]*7)|^[- \\(\\)]*8)([- \\(\\)]*[0-9]){10}$/';
  30. $regexp_replace = array('/^([- \\(\\)]*\\+[- \\(\\)]*7)/', '/[- \\(\\)]/');
  31. $replacement = array('8', '');
  32. $result = array();
  33. $i = 0;
  34. foreach ($lines as $number) {
  35. if (preg_match($regexp_control, $number)) {
  36. $result[$i] = preg_replace($regexp_replace, $replacement, $number);
  37. echo "Nomer OK, formatirovanie idet, zapis #$i\n";
  38. } else {
  39. echo "Error! $i\n";
  40. }
  41. ++$i;
  42. }
  43. var_dump($result);
Success #stdin #stdout 0s 52488KB
stdin
Standard input is empty
stdout
Nomer OK, formatirovanie idet, zapis #0
Nomer OK, formatirovanie idet, zapis #1
Nomer OK, formatirovanie idet, zapis #2
Nomer OK, formatirovanie idet, zapis #3
Nomer OK, formatirovanie idet, zapis #4
Nomer OK, formatirovanie idet, zapis #5
Nomer OK, formatirovanie idet, zapis #6
Nomer OK, formatirovanie idet, zapis #7
Nomer OK, formatirovanie idet, zapis #8
Nomer OK, formatirovanie idet, zapis #9
Nomer OK, formatirovanie idet, zapis #10
Nomer OK, formatirovanie idet, zapis #11
Error! 12
Error! 13
Error! 14
Error! 15
Error! 16
Error! 17
Error! 18
Error! 19
Error! 20
Error! 21
Error! 22
Error! 23
Error! 24
array(12) {
  [0]=>
  string(11) "84951234567"
  [1]=>
  string(11) "84951234567"
  [2]=>
  string(11) "84951234567"
  [3]=>
  string(11) "88122565656"
  [4]=>
  string(11) "89111234567"
  [5]=>
  string(11) "89111234567"
  [6]=>
  string(11) "89111234567"
  [7]=>
  string(11) "89111234567"
  [8]=>
  string(11) "89991234567"
  [9]=>
  string(11) "89091234567"
  [10]=>
  string(11) "89991234567"
  [11]=>
  string(11) "89525851255"
}