SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    springfield,IL
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quickform - formatting a Telephone Number

    I am using Quickform and one of my fields is a telephone number field. I pull this from an array field.

    phone=>1234567890

    In my quickform object, this is how I set it up.
    PHP Code:
    $form->addElement('text','phone','Phone:'); 
    It displays as...
    Phone: 1234567890

    I am able to retrieve the phone number as 10 digits, but when I display this value in Quickform, instead of seeing as 10 digits, how can I display as:

    Phone: (123) 456-7890

    I cant find any documentation how I can alter the format of the telephone number.

    Thanks in advance for your assistance.

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a function, from the PHP manual that formats phone numbers...

    http://us.php.net/manual/en/function.sscanf.php#57097

    If you know the phone number will always be 10 digits :

    sscanf($phone, "%3s%3s%4s", $area, $prefix, $exchange);

    echo "Phone : ($area) $prefix-$exchange";
    intragenesis, llc professional web & graphic design

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    springfield,IL
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by holmescreek View Post
    Here is a function, from the PHP manual that formats phone numbers...

    http://us.php.net/manual/en/function.sscanf.php#57097

    If you know the phone number will always be 10 digits :

    sscanf($phone, "%3s%3s%4s", $area, $prefix, $exchange);

    echo "Phone : ($area) $prefix-$exchange";
    holmescreek, Ill remember this in the future for this function. But in using Quickform layout, I dont think this will help. In Quickform, it doesnt use ECHO statements.

    Are you familiar with Quickform? I bought one of Sitepoints book called PHP Anthology and using the Quickform samples to build my forms. Unfortunately, it doesnt seem like to many people use this. The form example it gives is very basic.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •