fork download
  1. <?php
  2.  
  3. $rawPhone = "моб. 8(123) 123-4 5 6-7 без выходных";
  4. $regExp = '/(8|\\+7)([^0-9]*[0-9][^0-9]*[0-9][^0-9]*[0-9][^0-9]*)([^0-9]*[0-9][^0-9]*[0-9][^0-9]*[0-9][^0-9]*[0-9][^0-9]*[0-9][^0-9]*[0-9][^0-9]*[0-9])/';
  5. $matches = array();
  6. preg_match_all($regExp, $rawPhone, $matches);
  7.  
  8. if (empty($matches)) {
  9. die("Номер телефона не обнаружен");
  10. }
  11.  
  12. $cleanPhone = "8{$matches[2][0]}{$matches[3][0]}";
  13.  
  14. $regExpNums = '/[^0-9]/';
  15. $properPhone = preg_replace($regExpNums, "", $cleanPhone);
  16. echo $properPhone;
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
81231234567