src/Phone_number.php
public function format($phone_number = '', $format = '')
    {
        $inputParams = array(
            'phone_number' => $phone_number,
            'format'       => $format
        );
        $this->debug->info(__FUNCTION__, 'Input Params: ', $inputParams);
        if (empty($phone_number)) {
            $this->debug->warning(__FUNCTION__, 'Phone Number input is Empty!');

            return NULL;
        }
        $phone_number = trim($phone_number);
        $format       = strtoupper(trim($format));
        $hidden_list  = array(
            self::HIDDEN_REGION,
            self::HIDDEN_REGION_HEAD,
            self::HIDDEN_REGION_MIDDLE,
            self::HIDDEN_REGION_END
        );
        $this->debug->warning(__FUNCTION__, 'Hidden List Allowed: ', $hidden_list);
        try {
            $phoneNumberUtil   = PhoneNumberUtil::getInstance();
            $phoneNumberObject = $phoneNumberUtil->parse(trim($phone_number), self::DEFAULT_REGION);
            if ($format == self::DEFAULT_REGION) {
                $result = (string) '0' . $phoneNumberObject->getNationalNumber();
            } elseif (in_array($format, $hidden_list)) {
                $result = (string) $this->format_hidden($phone_number, $format);
            } elseif ($format == self::FORMAT_FOR_HUMAN_VIETNAM) {
                $result = (string) $phoneNumberUtil->formatOutOfCountryCallingNumber($phoneNumberObject, self::DEFAULT_COUNTRY);
            } elseif ($format == self::FORMAT_E164) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::E164);
            } elseif ($format == self::FORMAT_INTERNATIONAL) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
            } elseif ($format == self::FORMAT_NATIONAL) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::NATIONAL);
            } elseif ($format == self::FORMAT_RFC3966) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::RFC3966);
            } else {
                $result = (string) $phoneNumberObject->getCountryCode() . $phoneNumberObject->getNationalNumber();
            }
            $this->debug->debug(__FUNCTION__, 'Format Result: ' . $result . ' with Format: ' . $format);
            $this->debug->info(__FUNCTION__, 'Final Result: ' . $result);

            return $result;
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return $phone_number;
        }
    }
public function format($phone_number = '', $format = '')
    {
        $inputParams = array(
            'phone_number' => $phone_number,
            'format'       => $format
        );
        $this->debug->info(__FUNCTION__, 'Input Params: ', $inputParams);
        if (empty($phone_number)) {
            $this->debug->warning(__FUNCTION__, 'Phone Number input is Empty!');

            return NULL;
        }
        $phone_number = trim($phone_number);
        $format       = strtoupper(trim($format));
        $hidden_list  = array(
            self::HIDDEN_REGION,
            self::HIDDEN_REGION_HEAD,
            self::HIDDEN_REGION_MIDDLE,
            self::HIDDEN_REGION_END
        );
        $this->debug->warning(__FUNCTION__, 'Hidden List Allowed: ', $hidden_list);
        try {
            $phoneNumberUtil   = PhoneNumberUtil::getInstance();
            $phoneNumberObject = $phoneNumberUtil->parse(trim($phone_number), self::DEFAULT_REGION);
            if ($format == self::DEFAULT_REGION) {
                $result = (string) '0' . $phoneNumberObject->getNationalNumber();
            } elseif (in_array($format, $hidden_list)) {
                $result = (string) $this->format_hidden($phone_number, $format);
            } elseif ($format == self::FORMAT_FOR_HUMAN_VIETNAM) {
                $result = (string) $phoneNumberUtil->formatOutOfCountryCallingNumber($phoneNumberObject, self::DEFAULT_COUNTRY);
            } elseif ($format == self::FORMAT_E164) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::E164);
            } elseif ($format == self::FORMAT_INTERNATIONAL) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
            } elseif ($format == self::FORMAT_NATIONAL) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::NATIONAL);
            } elseif ($format == self::FORMAT_RFC3966) {
                $result = (string) $phoneNumberUtil->format($phoneNumberObject, \libphonenumber\PhoneNumberFormat::RFC3966);
            } else {
                $result = (string) $phoneNumberObject->getCountryCode() . $phoneNumberObject->getNationalNumber();
            }
            $this->debug->debug(__FUNCTION__, 'Format Result: ' . $result . ' with Format: ' . $format);
            $this->debug->info(__FUNCTION__, 'Final Result: ' . $result);

            return $result;
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return $phone_number;
        }
    }
Function Format
Format Phone Number with Format Style
Hàm cho phép Format số điện thoai theo format stype truyền vào

@author   : 713uk13m <dev@nguyenanhung.com>
@time     : 9/21/18 01:30

@param string $phone_number Input Phone Number
@param string $format       List command:
VN, VN_HUMAN,
E164,INTERNATIONAL, NATIONAL, RFC3966,
HIDDEN, HIDDEN_HEAD, HIDDEN_MIDDLE, HIDDEN_END

@example  phone_number = 0163 295 3760, format = Null or Invalid of List command => Output: 841632953760
@example  phone_number = 0163 295 3760, format = VN => Output: 01632953760
@example  phone_number = 0163 295 3760, format = VN_HUMAN => Output: 0163 295 3760
@example  phone_number = 0163 295 3760, format = NATIONAL => Output: 0163 295 3760
@example  phone_number = 0163 295 3760, format = INTERNATIONAL => Output: +84 163 295 3760
@example  phone_number = 0163 295 3760, format = E164 => Output: +841632953760
@example  phone_number = 0163 295 3760, format = RFC3966 => Output: tel:+84-163-295-3760
@example  phone_number = 0163 295 3760, format = HIDDEN => Output: 0163 *** 3760
@example  phone_number = 0163 295 3760, format = HIDDEN_HEAD => Output: **** 295 3760
@example  phone_number = 0163 295 3760, format = HIDDEN_MIDDLE => Output: 0163 *** 3760
@example  phone_number = 0163 295 3760, format = HIDDEN_END => Output: 0163 295 ****

@see      https://github.com/nguyenanhung/vn-telco-phonenumber/blob/master/test_phone_number.php
@see      https://github.com/giggsey/libphonenumber-for-php/blob/master/docs/PhoneNumberUtil.md

@return null|string String if Success, Null if Error, Raw phone input if Exception