fork(1) download
  1. <?php
  2.  
  3. $phoneNumber = "+7 (911) - 123 - 45 - 67";
  4. $regexpForMatching = "/^ *(\+ *7|8)([ ()-]*\d){10}$/";
  5. $regexpForPrefixSubstitution = "/\+ *7/";
  6. $regexpForSubstitution = "/[ ()-]/";
  7.  
  8. if (preg_match($regexpForMatching, $phoneNumber)){
  9. $result = preg_replace($regexpForPrefixSubstitution, "8", $phoneNumber);
  10. $result = preg_replace($regexpForSubstitution, "", $result);
  11. echo $result;
  12. }
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
89111234567