HomePHP Validating Octal and Hexadecimal Values with Filters in PHP 5
Validating Octal and Hexadecimal Values with Filters in PHP 5
As you know, when it comes to validating incoming data, PHP 5 comes bundled with a powerful set of native functions that allow you to perform all sorts of clever validations on a given variable. This includes checking for numeric values, arrays, strings, and objects as well. However, the best feature of the helpful validation capabilities offered by default by PHP 5 is its handy filter extension, even though it has been overlooked by many programmers so far.
Indeed, this library of filters also permits you to perform powerful validation on variables in a pretty straightforward fashion, without the need to define custom and complex functions. So, if you’re interested in learning how to use these filters within your own web applications, then this group of articles might be the material that you’re looking for.
Logically, if you already had the chance to read the introductory installment of this series, then at this point you’ll have a fairly clear idea of how to use the filter extension for validating integers. In that specific tutorial I coded a few basic examples that demonstrated how to carry out this task by using the FILTER_VALIDATE_INT filter in conjunction with the “filter_var()” function.
Not only did this filter allow us to check whether a given value was an integer or not, but it permitted us to determine if the value in question was within a specified range. This extra functionality was implemented via an additional “option” array, which was passed to the aforementioned “filter_var()” function.
However, I’m only scratching the surface when it comes to exploring the numerous capabilities offered by the filter extension. Therefore, in this second chapter of this series, I’m going to discuss how to use the FILTER_VALIDATE_INT filter that you learned in the previous part, this time for validating array elements as well as octal and hexadecimal integers.
Does this sound complex to you? It won’t be at all, trust me. Now, let’s get rid of the preliminaries and continue exploring the useful validation capacities of the filter PHP 5 extension!