<?php
$phoneNumber = "+7 (911) - 123 - 45 - 67";
$regexpForMatching = "/^ *(\+ *7|8)([ ()-]*\d){10}$/";
$regexpForPrefixSubstitution = "/\+ *7/";
$regexpForSubstitution = "/[ ()-]/";
if (preg_match($regexpForMatching, $phoneNumber)){ $result = preg_replace($regexpForPrefixSubstitution, "8", $phoneNumber); $result = preg_replace($regexpForSubstitution, "", $result); echo $result;
}
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKCiRwaG9uZU51bWJlciA9ICIrNyAoOTExKSAtIDEyMyAtIDQ1IC0gNjciOwokcmVnZXhwRm9yTWF0Y2hpbmcgPSAiL14gKihcKyAqN3w4KShbICgpLV0qXGQpezEwfSQvIjsKJHJlZ2V4cEZvclByZWZpeFN1YnN0aXR1dGlvbiA9ICIvXCsgKjcvIjsKJHJlZ2V4cEZvclN1YnN0aXR1dGlvbiA9ICIvWyAoKS1dLyI7CgppZiAocHJlZ19tYXRjaCgkcmVnZXhwRm9yTWF0Y2hpbmcsICRwaG9uZU51bWJlcikpewoJJHJlc3VsdCA9IHByZWdfcmVwbGFjZSgkcmVnZXhwRm9yUHJlZml4U3Vic3RpdHV0aW9uLCAiOCIsICRwaG9uZU51bWJlcik7CgkkcmVzdWx0ID0gcHJlZ19yZXBsYWNlKCRyZWdleHBGb3JTdWJzdGl0dXRpb24sICIiLCAkcmVzdWx0KTsKCWVjaG8gJHJlc3VsdDsKfQ==