format phone number
Posted: Thu Jun 27, 2002 12:35 pm
How can I format a string from a database like 9876543210 to appear as 987-654-3210? I am unfamiliar with regular expressions and not sure where to start.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$phone = 1234567890;
$newphone = substr($phone,0,3) . '-' . substr($phone,3,3) . '-' . substr($phone,6,4);