HomePHP Validating URL Protocols, Hosts and Paths with Filters in PHP 5
Validating URL Protocols, Hosts and Paths with Filters in PHP 5
When it comes to checking incoming data in web applications, PHP 5 provides developers with a huge arsenal of functions that permit them to perform this process in a pretty straightforward way. Indeed, checking integers and float numbers, IP and email addresses, alphabetic strings and so forth is a process that must be tackled frequently by programmers. Fortunately, validating data types is not a huge production with PHP.
PHP 5 comes bundled with a useful set of native filters that allow you to validate all sorts of data types without having to spend a long time coding custom functions. These filters are known popularly as the filter extension and offer a flat learning curve. Therefore, if you’re interested in learning how to get the most out of this extension and want to start using it when developing your own PHP programs, then this series of articles might be what you’re looking for.
Welcome to the sixth part of a series covering the use of filters in PHP 5. Comprised of nine tutorials, this series explores the most relevant filters that come with this handy library, and shows you with practical examples how to use them for checking strings and numeric values, email addresses and URLs, and many other common types of data.
And now that you've been introduced to the main subject of this series, it’s time to spend a few minutes reviewing the topics that were discussed in the last installment. In that particular tutorial I explained how to work with regular expressions by using the FILTER_VALIDATE_REGEXP filter in conjunction with the already familiar “filter_var()” function. Also, I showed how to validate well-formatted URLs at a very basic level by means of another helpful filter, not surprisingly called FILTER_VALIDATE_URL.
As I said, the validation process performed on URLs was pretty simplistic. Thus, in this sixth episode of the series I’m going to dig deeper into the usage of the FILTER_VALIDATE_URL filter to show you how to validate different portions of a URL, including its protocol, host and eventual paths.
So, are you ready to learn how to accomplish all of these useful things with the filter PHP 5 extension? Then let’s begin now!