Parsing a string into a boolean value in PHP

There is a native PHP method of doing this which uses PHP’s filter_var method:

$bool = filter_var($value, FILTER_VALIDATE_BOOLEAN);

According to PHP’s manual:

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

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)