{* *}
code teams

Phone Format



If you store a phone number as 7 or 10 digits. You can use this function to format the phone number or display.

function PhoneFormat($phone)
{
    if (strlen($phone) == 7)
    {
        $pref = substr($phone, 0,3);
        $numb = substr($phone, 3,4);
        $val = $pref . "-" . $numb;
        return $val;
    }
    else if (strlen($phone) == 10)
    {
        $ac   = substr($phone, 0,3);
        $pref = substr($phone, 3,3);
        $numb = substr($phone, 6,4);
        $val = "(" . $ac . ") " . $pref . "-" . $numb;
        return $val;
    }
    else
    {
        return $phone;
    }
 
}