How to make sure that a string contains a valid/well formed url?
I need be sure the url in the string is well formed.
It must contain http:// or https://
and .com or .org or .net or any other valid extension
I tried some of the answers found here in SO but all are accepting “www.google.com” as valid.
In my case the valid url needs to be http://http://www.google.com or https://http://www.google.com.
The www. part is not an obligation, since some urls dont use it.
Take a look at the answer here:
PHP regex for url validation, filter_var is too permisive
filter_var()could be just fine for you, but if you need something more powerful, you’ll have to use regex.Additionally with the code from here, you can sub-in any regex that suits your needs: