3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $sub = array( '+7 812-703-10-00', '8-812-346-60-01', '+7(495)785-98-42', '(499) 725 77 88', '8 (495) 663-61-00', '(812) 448-54-18', '8916-318-36-36', '540-69-05' ); foreach($sub as $s){ preg_match('/^(\+?\d+)?\s*(\(\d+\))?[\s-]*([\d-]*)$/', $s, $res); var_dump($res); }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(4) { [0]=> string(16) "+7 812-703-10-00" [1]=> string(2) "+7" [2]=> string(0) "" [3]=> string(13) "812-703-10-00" } array(4) { [0]=> string(15) "8-812-346-60-01" [1]=> string(1) "8" [2]=> string(0) "" [3]=> string(13) "812-346-60-01" } array(4) { [0]=> string(16) "+7(495)785-98-42" [1]=> string(2) "+7" [2]=> string(5) "(495)" [3]=> string(9) "785-98-42" } array(0) { } array(4) { [0]=> string(17) "8 (495) 663-61-00" [1]=> string(1) "8" [2]=> string(5) "(495)" [3]=> string(9) "663-61-00" } array(4) { [0]=> string(15) "(812) 448-54-18" [1]=> string(0) "" [2]=> string(5) "(812)" [3]=> string(9) "448-54-18" } array(4) { [0]=> string(14) "8916-318-36-36" [1]=> string(4) "8916" [2]=> string(0) "" [3]=> string(9) "318-36-36" } array(4) { [0]=> string(9) "540-69-05" [1]=> string(3) "540" [2]=> string(0) "" [3]=> string(5) "69-05" }