Welcome Guest, Not a member yet? Register   Sign In
Format Phone Numbers (Addition to string helper)
#1

[eluser]Iverson[/eluser]
In case anybody needs this...(US Phone Numbers)

Code:
function phone_format($str)
{
   // Keep only be digits
   $strPhone = ereg_replace("[^0-9]",'', $str);
   if(strlen($strPhone) != 10)
   {
      return $strPhone;
   }

   $strArea = substr($strPhone, 0, 3);
   $strPrefix = substr($strPhone, 3, 3);
   $strNumber = substr($strPhone, 6, 4);

   $strPhone = '(' . $strArea . ') ' . $strPrefix . '-' . $strNumber;

   return $strPhone;
}


Messages In This Thread
Format Phone Numbers (Addition to string helper) - by El Forum - 12-30-2008, 08:18 AM
Format Phone Numbers (Addition to string helper) - by El Forum - 12-30-2008, 01:15 PM
Format Phone Numbers (Addition to string helper) - by El Forum - 12-30-2008, 02:39 PM
Format Phone Numbers (Addition to string helper) - by El Forum - 12-30-2008, 02:50 PM
Format Phone Numbers (Addition to string helper) - by El Forum - 12-31-2008, 08:30 PM
Format Phone Numbers (Addition to string helper) - by El Forum - 01-01-2009, 03:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB