src/Phone_number.php
public function format_hidden($phone_number = '', $place_hidden = '')
    {
        $inputParams = array(
            'phone_number' => $phone_number,
            'place_hidden' => $place_hidden
        );
        $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);
        $place_hidden = strtoupper($place_hidden);
        try {
            $phoneNumberUtil     = PhoneNumberUtil::getInstance();
            $phoneNumberObject   = $phoneNumberUtil->parse(trim($phone_number), self::DEFAULT_REGION);
            $phoneNumberVnFormat = $phoneNumberUtil->formatOutOfCountryCallingNumber($phoneNumberObject, "VN");
            /**
             * Phone Number: 0163 123 456
             * $place_hidden = HEAD => **** 123 456
             * $place_hidden = MIDDLE => 0163 *** 456
             * $place_hidden = END => 0163 123 ***
             */
            $exPhone = explode(' ', $phoneNumberVnFormat);
            if (count($exPhone) > 1) {
                if ($place_hidden == self::HIDDEN_PLACE_HEAD) {
                    $result = trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[0]))) . trim($exPhone[1]) . trim($exPhone[2]);
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . self::HIDDEN_PLACE_HEAD);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                } elseif ($place_hidden == self::HIDDEN_PLACE_MIDDLE) {
                    $result = trim($exPhone[0]) . trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[1]))) . trim($exPhone[2]);
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . self::HIDDEN_PLACE_MIDDLE);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                } elseif ($place_hidden == self::HIDDEN_PLACE_END) {
                    $result = trim($exPhone[0]) . trim($exPhone[4]) . trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[2])));
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . self::HIDDEN_PLACE_END);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                } else {
                    $result = trim($exPhone[0]) . trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[1]))) . trim($exPhone[2]);
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . $place_hidden);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                }
            } else {
                $result = $phoneNumberVnFormat;
                $this->debug->debug(__FUNCTION__, 'Unavailable Hidden for ' . $place_hidden . ' with Phone Number: ' . $phone_number);
                $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
            }
            $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_hidden($phone_number = '', $place_hidden = '')
    {
        $inputParams = array(
            'phone_number' => $phone_number,
            'place_hidden' => $place_hidden
        );
        $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);
        $place_hidden = strtoupper($place_hidden);
        try {
            $phoneNumberUtil     = PhoneNumberUtil::getInstance();
            $phoneNumberObject   = $phoneNumberUtil->parse(trim($phone_number), self::DEFAULT_REGION);
            $phoneNumberVnFormat = $phoneNumberUtil->formatOutOfCountryCallingNumber($phoneNumberObject, "VN");
            /**
             * Phone Number: 0163 123 456
             * $place_hidden = HEAD => **** 123 456
             * $place_hidden = MIDDLE => 0163 *** 456
             * $place_hidden = END => 0163 123 ***
             */
            $exPhone = explode(' ', $phoneNumberVnFormat);
            if (count($exPhone) > 1) {
                if ($place_hidden == self::HIDDEN_PLACE_HEAD) {
                    $result = trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[0]))) . trim($exPhone[1]) . trim($exPhone[2]);
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . self::HIDDEN_PLACE_HEAD);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                } elseif ($place_hidden == self::HIDDEN_PLACE_MIDDLE) {
                    $result = trim($exPhone[0]) . trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[1]))) . trim($exPhone[2]);
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . self::HIDDEN_PLACE_MIDDLE);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                } elseif ($place_hidden == self::HIDDEN_PLACE_END) {
                    $result = trim($exPhone[0]) . trim($exPhone[4]) . trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[2])));
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . self::HIDDEN_PLACE_END);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                } else {
                    $result = trim($exPhone[0]) . trim(str_repeat(self::HIDDEN_STRING, strlen($exPhone[1]))) . trim($exPhone[2]);
                    $this->debug->debug(__FUNCTION__, 'Place Hidden is: ' . $place_hidden);
                    $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
                }
            } else {
                $result = $phoneNumberVnFormat;
                $this->debug->debug(__FUNCTION__, 'Unavailable Hidden for ' . $place_hidden . ' with Phone Number: ' . $phone_number);
                $this->debug->debug(__FUNCTION__, 'Result Hidden: ', $result);
            }
            $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_hidden
Format Hidden Phone number
Hàm cho phép format và ẩn đi 1 cụm số theo vị trí,
mỗi 1 số điện thoại sẽ chia ra 3 cụm, HEAD, MIDDLE và END

@author  : 713uk13m <dev@nguyenanhung.com>
@time    : 10/9/18 14:41

@param string $phone_number Input Phone Number
@param string $place_hidden Place Hidden: HEAD, MIDDLE or END

@example place_hidden = HEAD => **** 123 456
@example place_hidden = MIDDLE => 0163 *** 456
@example place_hidden = END => 0163 123 ***

@see     https://github.com/nguyenanhung/vn-telco-phonenumber/blob/master/test_phone_number.php

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