public static function formatPhone($phone)
    {
        $ddd = '';
        $phone = self::keepOnlyNumbers($phone);

        // removes leading zero
        if (substr($phone, 0, 1) == 0) {
            $phone = substr($phone, 1);
        }

        // verifies if have ddd
        if (strlen($phone) > 9) {    
            //removes country identifier
            if (strlen($phone) > 11) {
                $phone = substr($phone, 2);
            }
            $ddd = substr($phone, 0, 2);
            $phone = substr($phone, 2);
        }

        return ['areaCode' => $ddd, 'number' => $phone];
    }
public static function formatPhone($phone)
    {
        $ddd = '';
        $phone = self::keepOnlyNumbers($phone);

        // removes leading zero
        if (substr($phone, 0, 1) == 0) {
            $phone = substr($phone, 1);
        }

        // verifies if have ddd
        if (strlen($phone) > 9) {    
            //removes country identifier
            if (strlen($phone) > 11) {
                $phone = substr($phone, 2);
            }
            $ddd = substr($phone, 0, 2);
            $phone = substr($phone, 2);
        }

        return ['areaCode' => $ddd, 'number' => $phone];
    }
public static function formatPhone ( $ phone ) { $ ddd = '' ; $ phone = self :: keepOnlyNumbers ( $ phone ) ; // removes leading zero if ( substr ( $ phone , 0 , 1 ) == 0 ) { $ phone = substr ( $ phone , 1 ) ; } // verifies if have ddd if ( strlen ( $ phone ) > 9 ) { //removes country identifier if ( strlen ( $ phone ) > 11 ) { $ phone = substr ( $ phone , 2 ) ; } $ ddd = substr ( $ phone , 0 , 2 ) ; $ phone = substr ( $ phone , 2 ) ; } return [ 'areaCode' => $ ddd , 'number' => $ phone ] ; }
Format string phone number
@param string $phone
@return array of area code and number
Format string phone number