HomePHP Checking Boolean Values with Filters in PHP 5
Checking Boolean Values with Filters in PHP 5
Among the numerous libraries that come included by default with the PHP 5 distribution, there’s one that has been overlooked by many developers. This is a shame, because it can be really useful for validating incoming data in a truly simple fashion. I’m talking about the filter extension, a powerful set of functions that let programmers apply several filters to multiple PHP variables to perform all sorts of clever validations, ranging from checking for integer and float numbers, to verifying email addresses and URLs.
Therefore, if you feel curious and wish to learn how to incorporate the filter extension into your web developer’s toolbox, then don’t hesitate anymore; start reading this group of articles now!
Welcome to the third part of the series on using filters in PHP 5. Comprised of seven tutorials, this series gently introduces you to using the filter library that comes packaged with PHP 5. It shows you with numerous examples how to get the most out of each filter to perform strong validation on the inputted data handled by your web applications.
And now that you’re aware of the goal of this series, it’s time to review the topics that were covered in the last part of the series. So, in simple terms, during that particular article, I explained how to use the FILTER_VALIDATE_INT filter, in conjunction with the “filter_var()” function, to validate octal and hexadecimal integers. In both cases, a “flag” option was passed to the function to perform the data checking process.
Nonetheless, as I said before, the filter extension can be used for more than validating integers, since it provides the required functionality to checking other data types. Thus, in the next few lines I’m going to discuss how to use the extension for validating Boolean values. Does this sound good to you? Then please read the following section.