- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
FILTER_SANITIZE_NUMBER_FLOAT constant in PHP
The FILTER_SANITIZE_NUMBER_FLOAT constant deletes all illegal characters from a float number.
Flags
FILTER_FLAG_ALLOW_FRACTION − Allows fraction separator
FILTER_FLAG_ALLOW_THOUSAND − Allows thousand separator
FILTER_FLAG_ALLOW_SCIENTIFIC − Allows scientific notation
Return
The FILTER_SANITIZE_NUMBER_FLOAT constant does not return anything.
Example
The following is an example that use FILTER_FLAG_ALLOW_FRACTION flag.
<?php $var = "3-1f+2.56p"; var_dump(filter_var($var, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); ?>
Output
The following is the output.
string(8) "3-1+2.56"
Let us see another example. Here, FILTER_FLAG_ALLOW_THOUSAND flag is used −
Example
<?php $var = "1-4f+25,6p"; var_dump(filter_var($var, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND)); ?>
Output
Here is the output.
string(8) "1-4+25,6"
Advertisements