1$numbers = explode("\n", '(111) 222-3333
2((111) 222-3333
31112223333
4111 222-3333
5111-222-3333
6(111)2223333
7+11234567890
8 1-8002353551
9 123-456-7890 -Hello!
10+1 - 1234567890
11');
12
13
14foreach($numbers as $number)
15{
16 print preg_replace('~.*(\d{3})[^\d]{0,7}(\d{3})[^\d]{0,7}(\d{4}).*~', '($1) $2-$3', $number). "\n";
17}