FILTER_SANITIZE_NUMBER_FLOAT constant removes all illegal characters from floating point numbers.
FILTER_FLAG_ALLOW_FRACTION - allows fraction delimiter
FILTER_FLAG_ALLOW_THOUSAND - Allow thousands separators
FILTER_FLAG_ALLOW_SCIENTIFIC - Allow scientific notation
The FILTER_SANITIZE_NUMBER_FLOAT constant returns nothing.
The following is an example of using the FILTER_FLAG_ALLOW_FRACTION flag.
Real-time demonstration
<?php $var = "3-1f+2.56p"; var_dump(filter_var($var, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); ?>
The following is the output.
string(8) "3-1+2.56"
Let’s look at another example. The FILTER_FLAG_ALLOW_THOUSAND flag is used here -
Live Demonstration
<?php $var = "1-4f+25,6p"; var_dump(filter_var($var, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND)); ?>
This is the output.
string(8) "1-4+25,6"
The above is the detailed content of FILTER_SANITIZE_NUMBER_FLOAT constant in PHP. For more information, please follow other related articles on the PHP Chinese website!