The filter_var() function filters a variable with the specified filter.

Returns the filtered data on success or FALSE on failure.

Syntax

filter_var(variable, filter, options)
Optional. Specifies an associative array of flags/options or a single flag/option. Check each filter for possible options and flags
$int='123';
if(!filter_var($int,FILTER_VALIDATE_INT))
{
echo("integer is not valid");
}
else
{
echo ("integer is valid!");
}
输出valid

写options

$var=224;
$int_options=array("options"=>array("min_range"=>0,"max_range"=>256));
if(!filter_var($var,FILTER_VALIDATE_INT,$int_options))
{
echo "integer is not valid!";

}
else
{
echo "integer is valid!";
}

就像上面的代码一样,选项必须放入一个名为 "options" 的相关数组中。如果使用标志,则不需在数组内。

由于整数是 "300",它不在指定的氛围内,以上代码的输出将是 "Integer is not valid"。

相关文章:

  • 2021-11-04
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-12-05
  • 2021-11-03
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案