fork download
  1. <?php
  2.  
  3. $rawPhone = "+7(123 123-45 67";
  4. $rawPhone = trim($rawPhone);
  5.  
  6. $regExpProper = '/^(?:8|\\+7)((?:[\\s\\(\\)\\-]*[0-9]){10})$/';
  7. preg_match_all($regExpProper, $rawPhone, $matches);
  8.  
  9. if (empty($matches[0])) {
  10. echo "Ошибка при вводе телефона, попробуйте еще раз";
  11. } else {
  12. $regExpClean = '/[^0-9\\+]/';
  13. $cleanPhone = preg_replace($regExpClean, "", $matches[1][0]);
  14. $properPhone = "8{$cleanPhone}";
  15. echo $properPhone;
  16. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
81231234567