Corinne Shea wrote: >Hi, > >I'd like to write a function that will take a string of characters and >output it in a phone number format (xxx)xxx-xxxx and one for credit >cards xxxx-xxxx-xxxx-xxxx. > This is actually very easy to do if all you want to do is format, meaning you have already validated the data and can be assured that you have ten digits (or 16 for credit cards).
$phone_num="8005551212"; $formatted_phone_num="(" . substr($phone_num, "0", "3") . ") " . substr($phone_num, "3", "3") . "-" . substr($phone_num, "6", "4"); I'm sure there are other ways to achieve the same result, but you basically want to look at string functions that allow you to slice a phone number into whatever parts you want (area code, prefix, suffice for US numbers) and then create a string formatted however you want. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php