PHP FILTER_SANITIZE_NUMBER_FLOAT Filter
Definition and Usage
The FILTER_SANITIZE_NUMBER_FLOAT filter removes all illegal characters from floating-point numbers.
The filter allows all numbers as well as + and - by default.
- Name: "number_float"
- ID-number: 520
Possible Flags:
- FILTER_FLAG_ALLOW_FRACTION - Allows decimal separators (e.g., .)
- FILTER_FLAG_ALLOW_THOUSAND - Allows thousand separators (e.g., ,)
- FILTER_FLAG_ALLOW_SCIENTIFIC - Allows scientific notation (e.g., e and E)
Example
<?php
var_dump(filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT
,
FILTER_FLAG_ALLOW_FRACTION));
?>
Output:
string(7) "5-2+3.3"