DEV Community

Discussion on: Why PHP...???

Collapse
 
mikcat profile image
mikcat

What about using the filter_input function from php?

$orange = filter_input(INPUT_POST, 'orange', FILTER_VALIDATE_BOOLEAN);

Returns TRUE for "1", "true", "on" and "yes". Returns FALSE otherwise.

$orange = filter_input(INPUT_POST, 'orange', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

If FILTER_NULL_ON_FAILURE is set, FALSE is returned only for "0", "false", "off", "no", and "", and NULL is returned for all non-boolean values.