当前位置: 首页>>代码示例>>PHP>>正文


PHP format::read_floatval方法代码示例

本文整理汇总了PHP中format::read_floatval方法的典型用法代码示例。如果您正苦于以下问题:PHP format::read_floatval方法的具体用法?PHP format::read_floatval怎么用?PHP format::read_floatval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在format的用法示例。


在下文中一共展示了format::read_floatval方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 /**
  * Get information
  *
  * @param string $ip
  * @return array
  */
 public function get($ip)
 {
     $ip = $ip . '';
     // try to get IP information from cache
     $cache = new cache('db');
     $cache_id = 'misc_ip_ipinfo_' . $ip;
     $data = $cache->get($cache_id);
     if ($data !== false) {
         return ['success' => true, 'error' => [], 'data' => $data];
     }
     // if we need to query ipinfo.io
     $json = file_get_contents("http://ipinfo.io/{$ip}/json");
     $data = json_decode($json, true);
     if (isset($data['country'])) {
         $temp = explode(',', $data['loc']);
         $save = ['ip' => $ip, 'date' => format::now('date'), 'country' => $data['country'], 'region' => $data['region'], 'city' => $data['city'], 'postal' => $data['postal'], 'lat' => format::read_floatval($temp[0]), 'lon' => format::read_floatval($temp[1])];
         $cache->set($cache_id, $save, ['misc_ip_ipinfo'], 604800);
         return ['success' => true, 'error' => [], 'data' => $save];
     } else {
         return ['success' => false, 'error' => ['Could not decode IP address!'], 'data' => ['ip' => $ip]];
     }
 }
开发者ID:volodymyr-volynets,项目名称:backend,代码行数:28,代码来源:base.php

示例2: process_single_column_type

 /**
  * Process single type for column
  *
  * @param string $column_name
  * @param array $column_options
  * @param mixed $value
  * @return array
  */
 public static function process_single_column_type($column_name, $column_options, $value, $options = [])
 {
     $result = [];
     // processing as per different data types
     if ($column_options['type'] == 'boolean') {
         // booleans
         $result[$column_name] = !empty($value) ? 1 : 0;
     } else {
         if (in_array($column_options['type'], ['smallserial', 'serial', 'bigserial'])) {
             if (format::read_intval($value, ['valid_check' => 1])) {
                 $temp = format::read_intval($value);
                 if ($temp !== 0) {
                     $result[$column_name] = $temp;
                 }
             } else {
                 $result[$column_name . '_is_serial_error'] = true;
             }
             $result[$column_name . '_is_serial'] = true;
         } else {
             if (in_array($column_options['type'], ['smallint', 'integer', 'bigint'])) {
                 // integers
                 // if we got empty string we say its null
                 if (is_string($value) && $value === '') {
                     $value = null;
                 }
                 if (is_null($value)) {
                     if (!empty($column_options['null']) || !empty($options['ignore_defaults'])) {
                         $result[$column_name] = null;
                     } else {
                         $result[$column_name] = $column_options['default'] ?? 0;
                     }
                 } else {
                     $result[$column_name] = format::read_intval($value);
                 }
             } else {
                 if (in_array($column_options['type'], ['numeric', 'bcnumeric'])) {
                     // numerics as floats or strings
                     // if we got empty string we say its null
                     if (is_string($value) && $value == '') {
                         $value = null;
                     }
                     if (is_null($value)) {
                         if (!empty($column_options['null']) || !empty($options['ignore_defaults'])) {
                             $result[$column_name] = null;
                         } else {
                             $result[$column_name] = $column_options['default'] ?? ($column_options['type'] == 'bcnumeric' ? '0' : 0);
                         }
                     } else {
                         $result[$column_name] = format::read_floatval($value, ['bcnumeric' => $column_options['type'] == 'bcnumeric']);
                     }
                 } else {
                     if (in_array($column_options['type'], ['date', 'time', 'datetime', 'timestamp'])) {
                         $result[$column_name] = format::read_date($value, $column_options['type']);
                         // for datetime we do additional processing
                         if (!empty($options['process_datetime'])) {
                             $result[$column_name . '_strtotime_value'] = 0;
                             if (!empty($value)) {
                                 $result[$column_name . '_strtotime_value'] = strtotime($result[$column_name]);
                             }
                         }
                     } else {
                         if ($column_options['type'] == 'json') {
                             if (is_null($value)) {
                                 $result[$column_name] = null;
                             } else {
                                 if (is_array($value)) {
                                     $result[$column_name] = json_encode($value);
                                 } else {
                                     $result[$column_name] = (string) $value;
                                 }
                             }
                         } else {
                             if (is_null($value)) {
                                 $result[$column_name] = null;
                             } else {
                                 $result[$column_name] = (string) $value;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $result;
 }
开发者ID:volodymyr-volynets,项目名称:framework,代码行数:93,代码来源:columns.php

示例3: validate_data_types_single_value

 /**
  * Validate data type for single value
  *
  * @param string $k
  * @param array $v
  * @param mixed $in_value
  * @param string $error_field
  */
 public final function validate_data_types_single_value($k, $v, $in_value, $error_field = null)
 {
     // we set error field as main key
     if (empty($error_field)) {
         $error_field = $k;
     }
     // perform validation
     $data = object_table_columns::process_single_column_type($k, $v['options'], $in_value, ['process_datetime' => true]);
     if (array_key_exists($k, $data)) {
         // validations
         $error = false;
         $value = $in_value;
         // perform validation
         if ($v['options']['type'] == 'boolean') {
             if (!empty($value) && $value . '' != $data[$k] . '') {
                 $this->error('danger', 'Wrong boolean value!', $error_field);
                 $error = true;
             }
         } else {
             if (in_array($v['options']['type'], ['date', 'time', 'datetime', 'timestamp'])) {
                 // dates first
                 if (!empty($value) && empty($data[$k . '_strtotime_value'])) {
                     $this->error('danger', 'Invalid date, time or datetime!', $error_field);
                     $error = true;
                 }
             } else {
                 if ($v['options']['php_type'] == 'integer') {
                     if ($value . '' !== '' && !format::read_intval($value, ['valid_check' => 1])) {
                         $this->error('danger', 'Wrong integer value!', $error_field);
                         $error = true;
                     }
                     // null processing
                     if (!$error) {
                         if (empty($data[$k]) && !empty($v['options']['null'])) {
                             $data[$k] = null;
                         }
                     }
                 } else {
                     if ($v['options']['php_type'] == 'bcnumeric') {
                         // accounting numbers
                         if ($value . '' !== '' && !format::read_bcnumeric($value, ['valid_check' => 1])) {
                             $this->error('danger', 'Wrong numeric value!', $error_field);
                             $error = true;
                         }
                         // precision & scale validations
                         if (!$error) {
                             // validate scale
                             $digits = explode('.', $data[$k] . '');
                             if (!empty($v['options']['scale'])) {
                                 if (!empty($digits[1]) && strlen($digits[1]) > $v['options']['scale']) {
                                     $this->error('danger', 'Only [digits] fraction digits allowed!', $error_field, ['replace' => ['[digits]' => i18n(null, $v['options']['scale'])]]);
                                     $error = true;
                                 }
                             }
                             // validate precision
                             if (!empty($v['options']['precision'])) {
                                 $precision = $v['options']['precision'] - $v['options']['scale'] ?? 0;
                                 if (strlen($digits[0]) > $precision) {
                                     $this->error('danger', 'Only [digits] digits allowed!', $error_field, ['replace' => ['[digits]' => i18n(null, $precision)]]);
                                     $error = true;
                                 }
                             }
                         }
                     } else {
                         if ($v['options']['php_type'] == 'float') {
                             // regular floats
                             if ($value . '' !== '' && !format::read_floatval($value, ['valid_check' => 1])) {
                                 $this->error('danger', 'Wrong float value!', $error_field);
                                 $error = true;
                             }
                             // null processing
                             if (!$error) {
                                 if (empty($data[$k]) && !empty($v['options']['null'])) {
                                     $data[$k] = null;
                                 }
                             }
                         } else {
                             if ($v['options']['php_type'] == 'string') {
                                 // we need to convert empty string to null
                                 if ($data[$k] . '' === '' && !empty($v['options']['null'])) {
                                     $data[$k] = null;
                                 }
                                 // validate string length
                                 if ($data[$k] . '' !== '') {
                                     // validate length
                                     if (!empty($v['options']['type']) && $v['options']['type'] == 'char' && strlen($data[$k]) != $v['options']['length']) {
                                         // char
                                         $this->error('danger', 'The length must be [length] characters!', $error_field, ['replace' => ['[length]' => i18n(null, $v['options']['length'])]]);
                                         $error = true;
                                     } else {
                                         if (!empty($v['options']['length']) && strlen($data[$k]) > $v['options']['length']) {
                                             // varchar
//.........这里部分代码省略.........
开发者ID:volodymyr-volynets,项目名称:frontend,代码行数:101,代码来源:base.php


注:本文中的format::read_floatval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。