PHP FILTER_SANITIZE_NUMBER_FLOATFilter


PHP Filter 参考手册Complete PHP Filter Reference Manual

Definition and Usage

The FILTER_SANITIZE_NUMBER_FLOAT filter removes all illegal characters from a float number.

This filter allows all digits by default as well as + -

  • Name: "number_float"
  • ID-number: 520

Possible flags:

  • FILTER_FLAG_ALLOW_FRACTION - Allows the decimal separator (e.g., .)
  • FILTER_FLAG_ALLOW_THOUSAND - Allows the thousands separator (e.g., ,)
  • FILTER_FLAG_ALLOW_SCIENTIFIC - Allows scientific notation (e.g., e and E)

Examples

<?php
$number="5-2f+3.3pp";

var_dump(filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT,
FILTER_FLAG_ALLOW_FRACTION));
?>

The output of the code is shown below:

string(7) "5-2+3.3"


PHP Filter 参考手册Complete PHP Filter Reference Manual Other Extensions