protected function valueToPhone($mask, $value)
    {
        if (substr($value, 0, 1) == "*") { // if phone starts with "*", it's an international number, don't convert it
            return $value;
        }
        if (trim($value) == "") {
            return $value;
        }
        $maskLen = strlen($mask);
        $ph_len = strlen($value);
        $ph_fmt = $mask;
        $j = 0;
        for ($i = 0; $i < $maskLen; $i ++)
        {
            if ($mask[$i] == "#")
            {
                $ph_fmt[$i] = $value[$j];
                $j ++;
                if ($j == $ph_len) {
                    break;
                }
            }
        }
        return substr($ph_fmt, 0, $i + 1);
    }
protected function valueToPhone($mask, $value)
    {
        if (substr($value, 0, 1) == "*") { // if phone starts with "*", it's an international number, don't convert it
            return $value;
        }
        if (trim($value) == "") {
            return $value;
        }
        $maskLen = strlen($mask);
        $ph_len = strlen($value);
        $ph_fmt = $mask;
        $j = 0;
        for ($i = 0; $i < $maskLen; $i ++)
        {
            if ($mask[$i] == "#")
            {
                $ph_fmt[$i] = $value[$j];
                $j ++;
                if ($j == $ph_len) {
                    break;
                }
            }
        }
        return substr($ph_fmt, 0, $i + 1);
    }
protected function valueToPhone ( $ mask , $ value ) { if ( substr ( $ value , 0 , 1 ) == "*" ) { // if phone starts with "*", it's an international number, don't convert it return $ value ; } if ( trim ( $ value ) == "" ) { return $ value ; } $ maskLen = strlen ( $ mask ) ; $ ph_len = strlen ( $ value ) ; $ ph_fmt = $ mask ; $ j = 0 ; for ( $ i = 0 ; $ i < $ maskLen ; $ i ++ ) { if ( $ mask [ $ i ] == "#" ) { $ ph_fmt [ $ i ] = $ value [ $ j ] ; $ j ++ ; if ( $ j == $ ph_len ) { break ; } } } return substr ( $ ph_fmt , 0 , $ i + 1 ) ; }
Format value to phone number

@param string $fmt - type format
@param string $value - value
@return string - formatted string
Format value to phone number