fork(1) download
  1. <?php
  2.  
  3. $arr = array('84951234567', '+74951234567', '8-495-1-234-567', ' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67', '8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567', '8 ( 999 ) 1234567', '8 999 123 4567');
  4. $check = '#^(\\-|\\(|\\)| )*(([+](\\-|\\(|\\)| )*7)|8)((\\-|\\(|\\)| )*[0-9]){10}$#';
  5. $zamena = '#((\\-|\\(|\\)| )*([+](\\-|\\(|\\)| )*7))(\\-|\\(|\\)| )*#';
  6. $chistka = '#((\\-|\\(|\\)| )*){10}#';
  7. foreach ($arr as $input){
  8. if(preg_match($check, $input)){
  9. echo "Верно\n";
  10. }else{
  11. echo"Ошибка\n";
  12. }
  13.  
  14. $output1 = preg_replace($zamena, "8", $input);
  15. $outputFinal = preg_replace($chistka, "", $output1);
  16. echo $outputFinal."\n";}
  17.  
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
Верно
84951234567
Верно
84951234567
Верно
84951234567
Верно
88122565656
Верно
89111234567
Верно
89111234567
Верно
89111234567
Верно
89111234567
Верно
89991234567
Верно
89991234567
Верно
89991234567