Takes a ten digits string and breaks it into NPA (3 digits),
NXX (3 digits) and the actual phone number (4 digits).

Format: 234-234-2345

Returns an array with the keys npa, nxx and num.

@param $digits
18894
public static function normalizePhone($digits)
    {
        $chunks = str_split($digits, 3);

        $result['npa']   = $chunks[0];
        $result['nxx']   = $chunks[1];
        $result['num']   = $chunks[2].$chunks[3];
        $result['seven'] = $chunks[1].'-'.$chunks[2].$chunks[3];
        $result['plainseven'] = $chunks[1].$chunks[2].$chunks[3];
        $result['full']  = $chunks[0].'-'.$result['seven'];

        return $result;
    }
1142080
public static function php_number_format($number)
    {

        preg_match('/[.,](\d+)$/', $number, $matches);

        $num_decimals = strlen($matches[1]);

        return preg_replace('/[.,]/', '', $number) / pow(10, $num_decimals);
    }
1056678
private function numToString(BigNumber $number) : string
    {
        $output = '';
        while ($number->getValue() > 0) {
            $previousNumber = clone $number;
            $number = $number->divide($this->alphabetLength);
            $digit = $previousNumber->mod($this->alphabetLength);

            $output .= $this->alphabet[(int)$digit->getValue()];
        }

        return $output;
    }
1184839
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];
    }
345905
public static NumberFormat makeNumberFormat(int digits) {
    // Prefer predefined number formats where applicable.
    // TODO: cache others, too?
    switch(digits){
    case 0:
      return NF0;
    case 2:
      return NF2;
    case 3:
      return NF3;
    case 4:
      return NF4;
    case 6:
      return NF6;
    case 8:
      return NF8;
    }
    final NumberFormat nf = NumberFormat.getInstance(Locale.US);
    nf.setMaximumFractionDigits(digits);
    nf.setMinimumFractionDigits(digits);
    nf.setGroupingUsed(false);
    return nf;
  }
104374
public function phone($phone){
        $phone = $this->string($phone);
        $phone = trim($phone);
        $phone = preg_replace( "/[^0-9]/" , "" , $phone );
        $len = strlen( $phone );
        if( $len != 10 ){
            if( $len < 10 || $len > 11 ) { $phone = false; }
            if( $len == 11 ) {
                if( $phone[0] === "1" ) { $phone =  ltrim ( $phone , '1' ); }
                else{ $phone = false; }
            }
        }
        if( strlen($phone) == 10 ){ return $phone; }
        else{ return false; }
    }
971824
public static function decimalToAlphanumeric($number, $base = 64, $index = false)
    {
        if (!$base) {
            $base = strlen($index);
        } elseif (!$index) {
            $index = substr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, $base);
        }

        $out = "";

        for ($i = floor(log10($number) / log10($base)); $i >= 0; $i--) { 
            $no = floor($num/pow($base, $i));
            $out = $out.substr($index, $no, 1);
            $number = $number - ($no * pow($base, $i));
        }
        return $out;
    }
1279724
public static function mod10($number)
    {
        $checksum = '';
        foreach (str_split(strrev((string) $number)) as $i => $d) {
            $checksum .= ($i % 2 == 0) ? $d * 2 : $d;
        }
        return array_sum(str_split($checksum)) * 9 % 10;
    }
515525
private function number_format($number, $decimal_precision = 0, $decimals_separator = '.', $thousands_separator = ',') {
        $number = explode('.', str_replace(' ', '', $number));
        $number[0] = str_split(strrev($number[0]), 3);
        $total_segments = count($number[0]);
        for ($i = 0; $i < $total_segments; $i++) {
            $number[0][$i] = strrev($number[0][$i]);
        }
        $number[0] = implode($thousands_separator, array_reverse($number[0]));
        if (!empty($number[1])) {
           $number[1] = round($number[1], $decimal_precision);
        }
        return implode($decimals_separator, $number);
    }
1319061
public function formatStandardNumber($number, $decimals = null)
    {
        $lang = $this->request->getSession()->getLang();

        if ($decimals === null) {
            $decimals = $lang->getDecimals();
        }

        return number_format($number, $decimals, '.', '');
    }
1069402
private function isStandardBase(array $digits)
    {
        if (count($digits) > strlen(self::$standardBase)) {
            return false;
        }

        return $digits === str_split(substr(self::$standardBase, 0, count($digits)));
    }
117282
public function number($number, $decimals = null)
    {
        return number_format(
            (float) $number,
            $decimals,
            $this->getSymbol(self::DECIMAL_MARK),
            $this->getSymbol(self::THOUSANDS_SEPARATOR)
        );
    }
451288
public function number($number)
    {
        if ($number < 0) {
            $number   = -$number;
            $negative = self::NEGATIVE;
        } else {
            $negative = '';
        }
        $parts    = explode(self::DECIMAL, (string) $number, 2);
        $integers = $parts[0];
        if (strlen($integers) >= $this->digitsFirstGroup() + $this->minimumGroupingDigits()) {
            $todo     = substr($integers, 0, -$this->digitsFirstGroup());
            $integers = self::GROUP . substr($integers, -$this->digitsFirstGroup());
            while (strlen($todo) >= $this->digitsGroup() + $this->minimumGroupingDigits()) {
                $integers = self::GROUP . substr($todo, -$this->digitsGroup()) . $integers;
                $todo     = substr($todo, 0, -$this->digitsGroup());
            }
            $integers = $todo . $integers;
        }
        if (count($parts) > 1) {
            $decimals = self::DECIMAL . $parts[1];
        } else {
            $decimals = '';
        }

        return $this->digits($negative . $integers . $decimals);
    }
1327493
protected function set_digits(int $digits):void{

		if(!in_array($digits, [6, 8], true)){
			throw new AuthenticatorException('Invalid code length: '.$digits);
		}

		$this->digits = $digits;
	}
558391
protected function toWords($number, $power = 0)
    {
        $return = '';

        if ($number < 0) {
            $return = $this->minus . ' ';
            $number = (int) abs($number);
        }

        if ($number == 0 || $number == '') {
            return $this->wordSeparator . self::$digits[0];
        }

        $gt2000 = $number > 2000;

        if (strlen($number) > 3) {
            $maxp = strlen($number) - 1;
            $curp = $maxp;
            for ($p = $maxp; $p > 0; --$p) { // power
                if (isset(self::$exponent[$p])) {
                    // send substr from $curp to $p
                    $snum = substr($number, $maxp - $curp, $curp - $p + 1);
                    $snum = preg_replace('/^0+/', '', $snum);

                    if ($snum !== '') {
                        $return .= $this->toWords($snum, $p);

                        if ($gt2000) {
                            $return .= $this->thousandSeparator;
                        }
                    }
                    $curp = $p - 1;
                    continue;
                }
            }

            $number = substr($number, $maxp - $curp, $curp - $p + 1);

            if ($number == 0) {
                return rtrim($return, $this->thousandSeparator);
            }
        }

        $d = $number % 10;
        $t = (int) ($number / 10) % 10;
        $h = (int) ($number / 100) % 10;

        if ($h) {
            $return .= $this->wordSeparator . self::$digits[$h] . $this->wordSeparator . 'száz';
        }

        // ten, twenty etc.
        switch ($t) {
            case 9:
            case 5:
                $return .= $this->wordSeparator . self::$digits[$t] . 'ven';
                break;
            case 8:
            case 6:
                $return .= $this->wordSeparator . self::$digits[$t] . 'van';
                break;
            case 7:
                $return .= $this->wordSeparator . 'hetven';
                break;
            case 3:
                $return .= $this->wordSeparator . 'harminc';
                break;
            case 4:
                $return .= $this->wordSeparator . 'negyven';
                break;
            case 2:
                switch ($d) {
                    case 0:
                        $return .= $this->wordSeparator . 'húsz';
                        break;
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                        $return .= $this->wordSeparator . 'huszon';
                        break;
                }
                break;
            case 1:
                switch ($d) {
                    case 0:
                        $return .= $this->wordSeparator . 'tíz';
                        break;
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                        $return .= $this->wordSeparator . 'tizen';
                        break;
                }
                break;
        }

        if ($d > 0) {
            $return .= $this->wordSeparator . self::$digits[$d];
        }

        if ($power > 0) {
            if (isset(self::$exponent[$power])) {
                $lev = self::$exponent[$power];
            }

            if (!isset($lev) || !is_array($lev)) {
                return null;
            }

            $return .= $this->wordSeparator . $lev[0];
        }

        return $return;
    }
1250999
public static function getCheckDigit(string $number) : int
    {
        if (! ctype_digit($number)) {
            throw new \InvalidArgumentException('The number must be a string of digits');
        }

        $checksum = self::checksum($number . '0');

        return ($checksum === 0) ? 0 : 10 - $checksum;
    }
915855
public static function parse ($version)
    {
        $nums = explode(self::DELIMITER, $version);
        $numbers = array();
        foreach ($nums as $num) {
            if (preg_match('/^0*([0-9]+)/', $num, $matches)) {
                if (isset($matches[1])) {
                    $numbers[] = $matches[1];
                } else {
                    $numbers[] = 0;
                }
            } else {
                break;
            }
        }
        if (! sizeof($numbers)) {
            $numbers = array(0);
        }
        return $numbers;
    }