$re = '/^(\+?\d[\h(-]{0,3})? # Remove country code, "+", " ", and "("
(\d{3}) # Area code
[\h)-.]{0,3} # Remove "-", " ", ".", and ")"
(\d{3}) # Three digits
[\h-.]{0,3} # Remove "-", " ", and "."
(\d{4}) # Four digits/mx';
$str = '+1 123 111 1111
+1-111-111-1234
+1 (111) 111-1111
1 111 111 1111
1-111-111-1111
1-(111) 111-4567
1111111111
111.111.8765
111-345-1111';
$subst = "$2.$3.$4";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php