C regex for validating url
None of those is a URI, so a URI validator most certainly should not accept them.Just because browsers tend to understand them as a matter of a historical accident does not mean those are valid URIs, just as tag soup that browsers also tend to understand isn't valid HTML either. It's much simpler to write a URL validator by hand, speaking as someone who wrote a URL parser, and fixed a bug in PHP's.Or, you know, use a robust existing validator or parser. If you want to add more URLs to test, you can simply add them to the
There might still be a lot of functions that can be developed that are not featured here and are more accurate than this function, but so far this function ranks well in Google search.The Validation Functions to be Evaluated Searching Google for "validating URL PHP" or "PHP URL validation" (without quotes) yields the following six result,s which any developer can use and integrate into their own application:#1. Below is the summary for the rest of the validating functions: Based on the result, the first validating function (#1) produces the lowest average in terms of %slippage and %overjudgement.Source: The URLs to be Tested Below are the URLs to be tested against the above URL validating functions. Validating function #4 does have zero slippage, but it over-judges 87.5% of the time. The filter_validate_URL function, which is the #5 validating function, averages 31.62%. The six functions feature fairly similar testing scripts, such as the one shown below. query#fragment test the above functions properly, we need a PHP script that will serve as a vehicle for testing.