fork download
  1. <?php
  2. $regexp = '/^( ?8|\+ ?7)([ \-()]*[0-9]){10}$/';
  3. $number = "+ 7 ( 812 ) 678 - 67 - 67";
  4. echo $number . "\n";
  5.  
  6. if (preg_match($regexp, $number)) {
  7. $number = preg_replace("/[ \-()]/", '', $number);
  8. }
  9. if (preg_match("/\+7/", $number)) {
  10. $number = preg_replace("/\+7/", "8", $number);
  11. }
  12.  
  13. echo $number;
  14.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
+ 7 ( 812 ) 678 - 67 - 67
88126786767