fork download
  1. <?php
  2.  
  3. $rawPhone = "+7(123 123-45 67";
  4.  
  5. $regExpProper = '/(?:8|\\+7)((?:[\\s\\(\\)\\-]*[0-9]){10})/';
  6. preg_match_all($regExpProper, $rawPhone, $matches);
  7.  
  8. $regExpClean = '/[^0-9\\+]/';
  9. $cleanPhone = preg_replace($regExpClean, "", $matches[1][0]);
  10.  
  11. $properPhone = "8{$cleanPhone}";
  12.  
  13. echo $properPhone;
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
81231234567