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. Negative lookahead is used instead NOTE, that package does fuzzy search, not strict validation. If they copy it out and back into a browser so they may not know what's wrong with it upon visual inspection.
If the validation rules pass, your code will keep executing normally; however, if validation fails, an exception will be thrown and the proper error response will automatically be sent back to the user.
In the case of a traditional HTTP request, a redirect response will be generated, while a JSON response will be sent for AJAX requests. Again, if the validation fails, the proper response will automatically be generated.
There is also a bug in PHP 5.2.13 and PHP 5.3.2 that will not allow URLs with dashes in them to validate.
If you are unsure of your PHP version you can run php -v from the command line if you have command line PHP installed, or create a PHP file with the following contents and navigate to it using your web browser: There is a lot of debate about whether using a regular expression is a good idea when doing URL validation.
Each sampler (except Test Action) generates one or more sample results.
The sample results have various attributes (success/fail, elapsed time, data size etc.) and can be viewed in the various listeners.
This article will take a look at some of the most commonly used methods of validating URLs in PHP, the Regex method and the PHP built in Filter validate URL.
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.