fork(4) download
  1. <?php
  2. $regExp = "/^\\s*([+]\\s*7|8)(\W*[0-9]\W*){10}$/ui"; //регулярка для правильного номера (пока не нужна)
  3.  
  4.  
  5.  
  6. $exampleExp = "/\\W*/"; //регулярка для удаления лишних символов
  7.  
  8. $correctNumbers = [
  9. '84951234567', '+74951234567', '8-495-1-234-567',
  10. ' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67',
  11. '8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567',
  12. '8 ( 999 ) 1234567', '8 999 123 4567'
  13. ];
  14. foreach($correctNumbers as $correctNumber){
  15. echo preg_replace($exampleExp,"+7$2",$correctNumber);
  16. echo "\n";
  17. };
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
+78+74+79+75+71+72+73+74+75+76+77+7
+7+77+74+79+75+71+72+73+74+75+76+77+7
+78+7+74+79+75+7+71+7+72+73+74+7+75+76+77+7
+7+78+7+78+71+72+72+7+75+76+7+75+76+7+75+76+7
+78+7+79+71+71+7+71+72+73+74+75+76+77+7
+78+7+79+71+71+7+71+72+7+73+74+75+7+76+77+7
+78+7+79+71+71+7+71+72+7+73+74+75+7+76+77+7
+78+7+79+71+71+7+71+72+73+7+74+75+7+76+77+7
+7+77+7+79+79+79+7+71+72+73+7+74+75+76+77+7
+78+7+79+79+79+7+71+72+73+74+75+76+77+7
+78+7+79+79+79+7+71+72+73+7+74+75+76+77+7