If you haven’t had the chance to read the previous chapter of the series, where I coded a few basic examples showing how to validate URLs using the FILTER_VALIDATE_URL filter, you'll find those examples listed below. Here they are: (example on validating a well-formatted URL with the FILTER_VALIDATE_URL filter)
$url = 'http://www.devshed.com'; if(filter_var($url, FILTER_VALIDATE_URL) === FALSE) // displays The URL provided is valid. { echo 'The URL provided is not valid.'; } else { echo 'The URL provided is valid.'; }
(example on validating a badly-formatted URL with the FILTER_VALIDATE_URL filter)
$url = 'http://'; if(filter_var($url, FILTER_VALIDATE_URL) === FALSE) // displays The URL provided is not valid. { echo 'The URL provided is not valid.'; } else { echo 'The URL provided is valid.'; } As you may recall, performing basic validation on URLs with the FILTER_VALIDATE_URL filter is a very simple process that should be easy for you to grasp. In the code samples listed above, the filter is used in its simplest version, meaning that it’ll only check that the URLs being validated are well-formatted and nothing else. As I mentioned in the introduction, however, it's possible to instruct the filter to analyze different portions of a URL, including its protocol, host and paths, thus performing a more strict validation process. So, assuming that you’re interested in learning how to accomplish these helpful tasks, in the section to come I’m going to discuss how to utilize the FILTER_VALIDATE_URL filter in a more useful manner. As usual, to learn more on this specific topic, please click on the link that appears below and keep reading.
blog comments powered by Disqus |
|
|
|
|
|
|
|