views:

66

answers:

2

I think there is a bug in this filter_var or maybe I'm doing something wrong: Try this:

        $options = array(
            'options' => array(
                'default' => 3,
                'min_range' => 1000.0,
                'max_range' => 5000.6,
            )
        );

  $VariableValue2 = 5698;
  $VariableValue4 = 5698.2;

  $chicco3 = filter_var($VariableValue2, FILTER_VALIDATE_INT, $options);
  $chicco4 = filter_var($VariableValue4, FILTER_VALIDATE_FLOAT, $options);

It suppose to don't validate it... Infact the value: 5698 is greater than 5000.6!!!! But with FILTER_VALIDATE_INT it work FINE!! It return 3 that is the default value in case it don't validate it... PERFECT...

Instead, with FILTER_VALIDATE_FLOAT it validate it... It return 5698.2!!! I'm doing something wrong???

Thank you to everybody...

Samuele

+1  A: 

Check here; it looks like you're using the wrong options with the filter. The min_range and max_range options are for the filter_validate_int filter.

By the way, if you're just checking for the size of a number, it probably is easier to use some sort of

if( ( $number > 1000 ) && ( $number < 5000.6 ) )
    // do stuff;

mechanism instead.

eykanal
Ohh thanks a lot... I think you're right... But I thought it use the same options... So I can not validate the range of a float with the function: FILTER_VALIDATE_FLOAT ?It look like very strange that with FILTER_VALIDATE_INT you can do it and with FILTER_VALIDATE_FLOAT you can NOT do it...Anyway I will do it by me...Thanks again... :)
Samuele
@Samuele: API consistency is not exactly a PHP strong point.
webbiedave
I think so... :)
Samuele
+3  A: 

FILTER_VALIDATE_FLOAT does not accept a range option. Check the doc.

Arkh