bri0987 Posted November 19, 2007 Share Posted November 19, 2007 How can I change these two numbers into phone numbers? 5551231234 9009876789 echo INTO: (555) 123-1234 (900) 987-6789 Thanks, BRI Link to comment https://forums.phpfreaks.com/topic/77890-solved-change-straight-numbers-into-phone-numbers/ Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2007 Share Posted November 19, 2007 try the following $number = 5551231234; $number = preg_replace("/(\d{3})(\d{3})(\d{4})/","($1) $2-$3",$number); print $number; you can also achieve the same through substr Link to comment https://forums.phpfreaks.com/topic/77890-solved-change-straight-numbers-into-phone-numbers/#findComment-394255 Share on other sites More sharing options...
wsantos Posted November 19, 2007 Share Posted November 19, 2007 you can also achieve the same through substr That would be $phonenumber = "(" . substr($string,0,3) . ") " . substr($string,3,3) . "-" . substr($string,6,4); Link to comment https://forums.phpfreaks.com/topic/77890-solved-change-straight-numbers-into-phone-numbers/#findComment-394257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.