• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP filter_id函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中filter_id函数的典型用法代码示例。如果您正苦于以下问题:PHP filter_id函数的具体用法?PHP filter_id怎么用?PHP filter_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: testExpects

 public function testExpects()
 {
     //$ff = new FortissimoHarness(self::config);
     $cmd = new SimpleCommandTest('test');
     $expectations = $cmd->expects();
     $params = $expectations->params();
     $this->assertEquals(4, count($params), 'Command has four arguments');
     // Since params should be in order, we can shift them off the top:
     $testString = array_shift($params);
     $this->assertEquals('testString', $testString->getName());
     $this->assertEquals('A test string', $testString->getDescription());
     $testNumeric = array_shift($params);
     $this->assertEquals('testNumeric', $testNumeric->getName());
     // Count filters:
     $filters = $testNumeric->getFilters();
     $this->assertEquals(1, count($filters));
     $this->assertEquals('float', $filters[0]['type']);
     $this->assertNull($filters[0]['options']);
     // Manually execute a filter:
     $this->assertEquals(7.5, filter_var(7.5, filter_id($filters[0]['type']), NULL));
     // Test a failed filter:
     $this->assertFalse(filter_var('matt', filter_id($filters[0]['type']), NULL), 'String is not a float.');
     // Test callbacks
     $testNumeric2 = array_shift($params);
     $filters = $testNumeric2->getFilters();
     $this->assertEquals('callback', $filters[0]['type']);
     $this->assertTrue($filters[0]['options']['options'][0] instanceof SimpleValidatorTest, 'Option callback is a SimpleValidatorTest');
     $this->assertEquals(7, filter_var(3.5, FILTER_CALLBACK, $filters[0]['options']));
 }
开发者ID:masterminds,项目名称:fortissimo,代码行数:29,代码来源:BaseFortissimoCommandTest.php


示例2: doListFilters

 /**
  * Lists all filters available with the filter extension.
  */
 public function doListFilters()
 {
     $list = filter_list();
     foreach ($list as $filter) {
         echo filter_id($filter), ": {$filter}<br />\n";
     }
 }
开发者ID:laiello,项目名称:crindigan,代码行数:10,代码来源:hello.php


示例3: parseInputFromData

 private function parseInputFromData($useOverride)
 {
     $this->allElementsValid = true;
     foreach ($this->definition as $elementName => $inputElement) {
         $hasVariable = isset($this->inputData[$elementName]) || $useOverride == true && isset($_GET[$elementName]);
         if (!$hasVariable) {
             if ($inputElement->type === ezcInputFormDefinitionElement::REQUIRED) {
                 throw new ezcInputFormVariableMissingException($elementName);
             } else {
                 $this->properties[$elementName] = ezcInputForm::INVALID;
                 $this->allElementsValid = false;
                 continue;
             }
         }
         if ($useOverride == true && isset($_GET[$elementName])) {
             $flags = FILTER_NULL_ON_FAILURE | $inputElement->flags;
             $value = filter_var(isset($_GET[$elementName]) ? $_GET[$elementName] : null, filter_id($inputElement->filterName), array('options' => $inputElement->options, 'flags' => $flags));
         } else {
             $flags = FILTER_NULL_ON_FAILURE | $inputElement->flags;
             $value = filter_var($this->inputData[$elementName], filter_id($inputElement->filterName), array('options' => $inputElement->options, 'flags' => $flags));
         }
         if ($value !== null) {
             $this->properties[$elementName] = ezcInputForm::VALID;
             $this->propertyValues[$elementName] = $value;
         } else {
             $this->properties[$elementName] = ezcInputForm::INVALID;
             $this->allElementsValid = false;
         }
     }
 }
开发者ID:Adeelgill,项目名称:livehelperchat,代码行数:30,代码来源:lhform.php


示例4: getRegisteredFilters

 /**
  * Gets all possible filter types
  *
  * @return array
  */
 static function getRegisteredFilters()
 {
     if (empty(self::$filtersTypes)) {
         foreach (filter_list() as $filter_name) {
             self::$filtersTypes[filter_id($filter_name)] = $filter_name;
         }
     }
     return self::$filtersTypes;
 }
开发者ID:phoebius,项目名称:proof-of-concept,代码行数:14,代码来源:Filter.class.php


示例5: generator_file

/**
 * Generates a unique file name in given path
 *
 * @param string $str
 * @param string $path
 *
 * @return string
 */
function generator_file(string $str, string $path) : string
{
    $parts = explode('.', $str);
    $ext = array_pop($parts);
    $str = filter_id(implode('-', $parts));
    if (file_exists($path . '/' . $str . '.' . $ext)) {
        $str .= '-';
        for ($i = 1; file_exists($path . '/' . $str . $i . '.' . $ext); $i++) {
        }
        $str .= $i;
    }
    return $str . '.' . $ext;
}
开发者ID:akilli,项目名称:qnd,代码行数:21,代码来源:generator.php


示例6: get

 /**
  * @param string $name
  * @param int $filter
  * @param array|null $options
  * @return mixed
  */
 public function get($name, $filter = FILTER_DEFAULT, $options = null)
 {
     if (is_string($filter)) {
         $filter = filter_id($filter);
     }
     if ($this->data !== null) {
         if (array_key_exists($name, $this->data)) {
             $value = filter_var($this->data[$name], $filter, $options);
         } else {
             $value = $this->optionFlags($options) & FILTER_NULL_ON_FAILURE ? false : null;
         }
     } else {
         $value = filter_input($this->type, $name, $filter, $options);
     }
     return $value;
 }
开发者ID:rakorium,项目名称:okapi,代码行数:22,代码来源:Source.php


示例7: __construct

	public function __construct($reqArgs, Array $sieve) {    
		$valueArr = array_merge($_GET, $_POST, $reqArgs);        

		foreach ($valueArr as $k => $v) {       			
			if (isset($sieve[$k])) {
				$this->_gpVars[$k]['value'] = filter_var($valueArr[$k], filter_id($sieve[$k]));  
				$this->_gpVars[$k]['sieved'] = true; 
			} 
			$this->_gpVars[$k]['value'] = $v;			
			unset($sieve[$k]);
		}               
 
		if (0 !== count(array_keys($sieve))) {
			throw new \Exception("Expected params were not given.");
		}
	}
开发者ID:nforgerit,项目名称:upstream,代码行数:16,代码来源:Sanitizer.php


示例8: filter

 /**
  * 使用filter_var方式验证
  * @access protected
  * @param mixed $value  字段值
  * @param mixed $rule  验证规则
  * @return bool
  */
 protected function filter($value, $rule)
 {
     if (is_string($rule) && strpos($rule, ',')) {
         list($rule, $param) = explode(',', $rule);
     } elseif (is_array($rule)) {
         $param = isset($rule[1]) ? $rule[1] : null;
     } else {
         $param = null;
     }
     return false !== filter_var($value, is_int($rule) ? $rule : filter_id($rule), $param);
 }
开发者ID:livingvirus,项目名称:cyfthink,代码行数:18,代码来源:Validate.php


示例9: filterPHP

 public function filterPHP($options)
 {
     if (!count($options)) {
         throw new \RuntimeException('Missing mandatory option: filter name');
     }
     $name = $options[0];
     return function (&$field) use($name) {
         if ($field !== '') {
             $filtered = filter_var($field, filter_id($name));
             if ($filtered === FALSE) {
                 return FALSE;
             }
             $field = $filtered;
         }
         return TRUE;
     };
 }
开发者ID:pixel418,项目名称:eloq,代码行数:17,代码来源:FormInputFilter.php


示例10: filter

 /**
  * 递归过滤给定的值
  * @param mixed $value 键值
  * @param mixed $key 键名
  * @param array $filters 过滤方法+默认值
  * @return mixed
  */
 private static function filter(&$value, $key, $filters)
 {
     // 分离出默认值
     $default = array_pop($filters);
     foreach ($filters as $filter) {
         if (is_callable($filter)) {
             // 调用函数过滤
             $value = call_user_func($filter, $value);
         } else {
             $begin = substr($filter, 0, 1);
             if (in_array($begin, ['/', '#', '~']) && $begin == ($end = substr($filter, -1))) {
                 // 正则过滤
                 if (!preg_match($filter, $value)) {
                     // 匹配不成功返回默认值
                     $value = $default;
                     break;
                 }
             } else {
                 // filter函数不存在时, 则使用filter_var进行过滤
                 // filter为非整形值时, 调用filter_id取得过滤id
                 $value = filter_var($value, is_int($filter) ? $filter : filter_id($filter));
                 if (false === $value) {
                     // 不通过过滤器则返回默认值
                     $value = $default;
                     break;
                 }
             }
         }
     }
     self::filterExp($value);
 }
开发者ID:Tong12,项目名称:think,代码行数:38,代码来源:Input.php


示例11: getData

 /**
  * 获取系统变量 支持过滤和默认值
  * @access   public
  *
  * @param $name
  * @param $input
  * @param $filter
  * @param $default
  *
  * @return mixed
  * @internal param string $method 输入数据类型
  * @internal param array $args 参数 [key,filter,default]
  */
 private static function getData($name, $input, $filter, $default)
 {
     if (strpos($name, '/')) {
         // 指定修饰符
         list($name, $type) = explode('/', $name, 2);
     } else {
         // 默认强制转换为字符串
         $type = 's';
     }
     $filters = isset($filter) ? $filter : self::$filter;
     if ('' == $name) {
         // 获取全部变量
         $data = $input;
         if ($filters) {
             if (is_string($filters)) {
                 $filters = explode(',', $filters);
             }
             foreach ($filters as $filter) {
                 $data = self::filter($filter, $data);
                 // 参数过滤
             }
         }
     } elseif (isset($input[$name])) {
         // 取值操作
         $data = $input[$name];
         if ($filters) {
             if (is_string($filters)) {
                 if (0 === strpos($filters, '/')) {
                     if (1 !== preg_match($filters, (string) $data)) {
                         // 支持正则验证
                         return $default;
                     }
                 } else {
                     $filters = explode(',', $filters);
                 }
             } elseif (is_int($filters)) {
                 $filters = [$filters];
             }
             if (is_array($filters)) {
                 foreach ($filters as $filter) {
                     if (function_exists($filter)) {
                         $data = is_array($data) ? self::filter($filter, $data) : $filter($data);
                         // 参数过滤
                     } else {
                         $data = filter_var($data, is_int($filter) ? $filter : filter_id($filter));
                         if (false === $data) {
                             return $default;
                         }
                     }
                 }
             }
         }
         if (!empty($type)) {
             switch (strtolower($type)) {
                 case 'a':
                     // 数组
                     $data = (array) $data;
                     break;
                 case 'd':
                     // 数字
                     $data = (int) $data;
                     break;
                 case 'f':
                     // 浮点
                     $data = (double) $data;
                     break;
                 case 'b':
                     // 布尔
                     $data = (bool) $data;
                     break;
                 case 's':
                     // 字符串
                 // 字符串
                 default:
                     $data = (string) $data;
             }
         }
     } else {
         // 变量默认值
         $data = $default;
     }
     is_array($data) && array_walk_recursive($data, 'self::filterExp');
     return $data;
 }
开发者ID:guozqiu,项目名称:think,代码行数:97,代码来源:input.php


示例12: applyFilter

 /**
  * @param mixed $value
  * @param array $spec
  * @return boolean
  */
 protected function applyFilter($value, $spec)
 {
     $result = true;
     $filter = $spec['filter'];
     //
     if (is_callable($filter)) {
         $result = $filter($value, $this->filterOptions($spec));
     } elseif (is_numeric($filter)) {
         $result = filter_var($value, $filter, $this->filterOptions($spec));
     } elseif (is_string($filter)) {
         $id = filter_id($filter);
         if ($id === false) {
             $result = false;
             $spec['message'] = "Unknown filter '{$filter}'";
         } else {
             $result = filter_var($value, $id, $this->filterOptions($spec));
         }
     } else {
         $result = false;
     }
     return $result;
 }
开发者ID:rakorium,项目名称:okapi,代码行数:27,代码来源:Input.php


示例13: I


//.........这里部分代码省略.........
    if (strpos($name, '.')) {
        // 指定参数来源
        list($method, $name) = explode('.', $name, 2);
    } else {
        // 默认为自动判断
        $method = 'param';
    }
    switch (strtolower($method)) {
        case 'get':
            $input =& $_GET;
            break;
        case 'post':
            $input =& $_POST;
            break;
        case 'put':
            parse_str(file_get_contents('php://input'), $input);
            break;
        case 'param':
            switch ($_SERVER['REQUEST_METHOD']) {
                case 'POST':
                    $input = $_POST;
                    break;
                case 'PUT':
                    parse_str(file_get_contents('php://input'), $input);
                    break;
                default:
                    $input = $_GET;
            }
            break;
        case 'path':
            $input = array();
            if (!empty($_SERVER['PATH_INFO'])) {
                $depr = C('URL_PATHINFO_DEPR');
                $input = explode($depr, trim($_SERVER['PATH_INFO'], $depr));
            }
            break;
        case 'request':
            $input =& $_REQUEST;
            break;
        case 'session':
            $input =& $_SESSION;
            break;
        case 'cookie':
            $input =& $_COOKIE;
            break;
        case 'server':
            $input =& $_SERVER;
            break;
        case 'globals':
            $input =& $GLOBALS;
            break;
        case 'data':
            $input =& $datas;
            break;
        default:
            return NULL;
    }
    if ('' == $name) {
        // 获取全部变量
        $data = $input;
        array_walk_recursive($data, 'filter_exp');
        $filters = isset($filter) ? $filter : C('DEFAULT_FILTER');
        if ($filters) {
            if (is_string($filters)) {
                $filters = explode(',', $filters);
            }
            foreach ($filters as $filter) {
                $data = array_map_recursive($filter, $data);
                // 参数过滤
            }
        }
    } elseif (isset($input[$name])) {
        // 取值操作
        $data = $input[$name];
        is_array($data) && array_walk_recursive($data, 'filter_exp');
        $filters = isset($filter) ? $filter : C('DEFAULT_FILTER');
        if ($filters) {
            if (is_string($filters)) {
                $filters = explode(',', $filters);
            } elseif (is_int($filters)) {
                $filters = array($filters);
            }
            foreach ($filters as $filter) {
                if (function_exists($filter)) {
                    $data = is_array($data) ? array_map_recursive($filter, $data) : $filter($data);
                    // 参数过滤
                } else {
                    $data = filter_var($data, is_int($filter) ? $filter : filter_id($filter));
                    if (false === $data) {
                        return isset($default) ? $default : NULL;
                    }
                }
            }
        }
    } else {
        // 变量默认值
        $data = isset($default) ? $default : NULL;
    }
    return $data;
}
开发者ID:terrydeng,项目名称:beimeibang1205,代码行数:101,代码来源:functions+-+Copy.php


示例14: filterValue

 /**
  * Filters a value according to filter, filter_id and options
  *
  * @param mixed     $value
  * @param mixed     $filter
  * @param int       $filterId
  * @param mixed     $options
  * @return mixed
  */
 protected function filterValue($value, $filter, $filterId, $options)
 {
     if (!$filter && !$filterId) {
         return $value;
     }
     if (null === $filterId && is_string($filter)) {
         $filterId = is_string($filter) ? filter_id($filter) : null;
     }
     if ($filterId) {
         if (null === $options) {
             $value = filter_var($value, $filterId);
         } else {
             $value = filter_var($value, $filterId, array('options' => $options));
         }
     } elseif (is_callable($filter)) {
         $value = call_user_func($filter, $value);
     }
     return $value;
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:28,代码来源:Config.php


示例15: id

 public function id(string $filterName) : int
 {
     return filter_id($filterName);
 }
开发者ID:znframework,项目名称:znframework,代码行数:4,代码来源:InternalFilters.php


示例16: check

 /**
  * 验证数据 支持 in between equal length regex expire ip_allow ip_deny
  * @access public
  * @param string $value 验证数据
  * @param mixed $rule 验证表达式
  * @param string $type 验证方式 默认为正则验证
  * @return boolean
  */
 public function check($value, $rule, $type = 'regex')
 {
     $type = strtolower(trim($type));
     switch ($type) {
         case 'in':
             // 验证是否在某个指定范围之内 逗号分隔字符串或者数组
         // 验证是否在某个指定范围之内 逗号分隔字符串或者数组
         case 'notin':
             $range = is_array($rule) ? $rule : explode(',', $rule);
             return 'in' == $type ? in_array($value, $range) : !in_array($value, $range);
         case 'between':
             // 验证是否在某个范围
         // 验证是否在某个范围
         case 'notbetween':
             // 验证是否不在某个范围
             if (is_array($rule)) {
                 $min = $rule[0];
                 $max = $rule[1];
             } else {
                 list($min, $max) = explode(',', $rule);
             }
             return 'between' == $type ? $value >= $min && $value <= $max : $value < $min || $value > $max;
         case 'equal':
             // 验证是否等于某个值
         // 验证是否等于某个值
         case 'notequal':
             // 验证是否等于某个值
             return 'equal' == $type ? $value == $rule : $value != $rule;
         case 'length':
             // 验证长度
             $length = mb_strlen($value, 'utf-8');
             // 当前数据长度
             if (strpos($rule, ',')) {
                 // 长度区间
                 list($min, $max) = explode(',', $rule);
                 return $length >= $min && $length <= $max;
             } else {
                 // 指定长度
                 return $length == $rule;
             }
         case 'expire':
             list($start, $end) = explode(',', $rule);
             if (!is_numeric($start)) {
                 $start = strtotime($start);
             }
             if (!is_numeric($end)) {
                 $end = strtotime($end);
             }
             return NOW_TIME >= $start && NOW_TIME <= $end;
         case 'ip_allow':
             // IP 操作许可验证
             return in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule));
         case 'ip_deny':
             // IP 操作禁止验证
             return !in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule));
         case 'filter':
             // 使用filter_var验证
             $result = filter_var($value, is_int($rule) ? $rule : filter_id($rule));
             return false === $result ? false : true;
         case 'regex':
         default:
             // 默认使用正则验证 可以使用验证类中定义的验证名称
             // 检查附加规则
             return $this->regex($value, $rule);
     }
 }
开发者ID:poettian,项目名称:think,代码行数:74,代码来源:Auto.php


示例17: var_dump

<?php

var_dump(filter_id("stripped"));
var_dump(filter_id("string"));
var_dump(filter_id("url"));
var_dump(filter_id("int"));
var_dump(filter_id("none"));
var_dump(filter_id(array()));
var_dump(filter_id(-1));
var_dump(filter_id(0, 0, 0));
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:11,代码来源:009.php


示例18: I

/**
 * 获取输入参数 支持过滤和默认值
 * 使用方法:
 * <code>
 * I('id',0); 获取id参数 自动判断get或者post
 * I('post.name','','htmlspecialchars'); 获取$_POST['name']
 * I('get.'); 获取$_GET
 * </code>
 * @param string $name 变量的名称 支持指定类型
 * @param mixed $default 不存在的时候默认值
 * @param mixed $filter 参数过滤方法
 * @return mixed
 */
function I($name = null, $default = '', $filter = null)
{
    $touch =& get_instance();
    if (strpos($name, '.')) {
        // 指定参数来源
        list($method, $name) = explode('.', $name, 2);
    } else {
        // 默认为自动判断
        $method = 'param';
    }
    $path_info = $touch->uri->ruri_to_assoc();
    $_GET = array_merge($_GET, $path_info);
    switch (strtolower($method)) {
        case 'get':
            $input =& $_GET;
            break;
        case 'post':
            $input =& $_POST;
            break;
        case 'put':
            parse_str(file_get_contents('php://input'), $input);
            break;
        case 'param':
            switch ($_SERVER['REQUEST_METHOD']) {
                case 'POST':
                    $input = $_POST;
                    break;
                case 'PUT':
                    parse_str(file_get_contents('php://input'), $input);
                    break;
                default:
                    $input = $_GET;
            }
            break;
        case 'request':
            $input =& $_REQUEST;
            break;
        case 'session':
            $input =& $_SESSION;
            break;
        case 'cookie':
            $input =& $_COOKIE;
            break;
        case 'server':
            $input =& $_SERVER;
            break;
        case 'globals':
            $input =& $GLOBALS;
            break;
        default:
            return NULL;
    }
    if (empty($name)) {
        // 获取全部变量
        $data = $input;
        $filters = isset($filter) ? $filter : 'htmlspecialchars';
        if ($filters) {
            $filters = explode(',', $filters);
            foreach ($filters as $filter) {
                $data = array_map($filter, $data);
                // 参数过滤
            }
        }
    } elseif (isset($input[$name])) {
        // 取值操作
        $data = $input[$name];
        $filters = isset($filter) ? $filter : 'htmlspecialchars';
        if ($filters) {
            $filters = explode(',', $filters);
            foreach ($filters as $filter) {
                if (function_exists($filter)) {
                    $data = is_array($data) ? array_map_recursive($filter, $data) : $filter($data);
                    // 参数过滤
                } else {
                    $data = filter_var($data, is_int($filter) ? $filter : filter_id($filter));
                    if (false === $data) {
                        return isset($default) ? $default : NULL;
                    }
                }
            }
        }
    } else {
        // 变量默认值
        $data = isset($default) ? $default : NULL;
    }
    is_array($data) && array_walk_recursive($data, 'touch_filter');
    return $data;
//.........这里部分代码省略.........
开发者ID:connwap135,项目名称:ectouch,代码行数:101,代码来源:function_helper.php


示例19: filter

 /**
  * 使用filter_var方式验证
  * @access public
  * @param mixed $value  字段值
  * @param mixed $rule  验证规则
  * @param array $params  参数
  * @return bool
  */
 public static function filter($value, $rule, $params = [])
 {
     return false !== filter_var($value, is_int($rule) ? $rule : filter_id($rule), $params);
 }
开发者ID:klsf,项目名称:kldns,代码行数:12,代码来源:Validate.php


示例20: id

 public function id($filterName = '')
 {
     if (!is_string($filterName)) {
         return Error::set('Error', 'stringParameter', '1.(filterName)');
     }
     return filter_id($filterName);
 }
开发者ID:bytemtek,项目名称:znframework,代码行数:7,代码来源:Filters.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP filter_input函数代码示例发布时间:2022-05-15
下一篇:
PHP filter_has_var函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap