FILTER_VALIDATE_FLOAT

By using FILTER_VALIDATE_FLOAT we can validate variables to check if float data is present or not.
$price=12.32; // Change this value to get different result
if(filter_var($price,FILTER_VALIDATE_FLOAT)){ echo " Yes validation passed "; }else{ echo " No validation failed "; }
By using filter id of FILTER_VALIDATE_FLOAT the same script can be written as
if(filter_var($price,259)){

Difference between FILTER_VALIDATE_FLOAT and FILTER_VALIDATE_INT

$var=12.34;
if(filter_var($var, FILTER_VALIDATE_FLOAT)){
echo "Yes true for FILTER_VALIDATE_FLOAT: $var";
}else{
echo "No false FILTER_VALIDATE_FLOAT: $var";
}
Output is
Yes true for FILTER_VALIDATE_FLOAT: 12.34
Now using FILTER_VALIDATE_INT
$var=12.34;
if(filter_var($var, FILTER_VALIDATE_INT)){
echo "Yes true for FILTER_VALIDATE_INT: $var";
}else{
echo "No false FILTER_VALIDATE_INT: $var";
}
Output is
No false FILTER_VALIDATE_INT: 12.34


plus2net.com




Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer