forked from bcit-ci/CodeIgniter
-
Notifications
You must be signed in to change notification settings - Fork 4
Format US Phone Number
g1smd edited this page Sep 2, 2012
·
1 revision
Category:Helper::Community | Category:Helper::Phone Numbers
/**
* CodeIgniter My Text Helpers
*
* @package CodeIgniter
* @subpackage Helpers
* @category Helpers
* @author Hermawan Haryanto
* @link not yet approved
*/
/**
* US Phone Number Formating
*
* Format Integer into US Phone Number
* (xxx) xxx-xxxx
*
* @access public
* @param string
* @return string
*/
function phone ($str)
{
$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);
}