If you are uncertain and looking for a guide then this may help: If you are using a version of PHP that is older than PHP 5.2: - Use the regular expression approach If you are using PHP 5.2.13 or PHP 5.3.2 and need URLs with dashes to validate: - Use the regular expression approach If you don't fall into one of the above categories: - Use the filter_var() approach Note: Some have complained that using the PHP filter_var() function is too permissive and allows URLs that should not validate.
In some cases the url may not actually have a resource at its location available yet (e.g.
creating a url to an image that has yet to be uploaded). :// # http or https protocol | # or www\d[.] # " "www1.", "www2." …
Validating URLs is important to form handling and PHP data processing.
Currently there are numerous solutions for validating URLs. the real issuse is that both methods dont check for "FILTER_FLAG_HOST_REQUIRED" which actually doesent work altough it should check ending... I have been trying to find a good solution for testing for URL's, I would not use the filter_var() for this kind of check. The only way i have found to check for them is either use regex or use the parse_url and check each section.
The important point is to pick the right tool (regex or otherwise) for the job and not be specifically "anti" or "pro" regex.