First lets define a "URL" according to my requirements.
The only protocols optionally allowed are http://
and https://
then a mandatory domain name like stackoverflow.com
then optionally the rest of url components (path
, query
, hash
, ...)
For reference a list of valid and invalid url's according to my requirements
VALID
- stackoverflow.com
- stackoverflow.com/questions/ask
- http://stackoverflow.com/questions/ask
- http://www.amazon.com/Computers-Internet-Books/b/ref=bhp_bb0309A_comint2?ie=UTF8&node=5&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=browse&pf_rd_r=0AH7GM29WF81Q72VPFDH&pf_rd_t=101&pf_rd_p=1273387142&pf_rd_i=283155
amazon.com/Computers-Internet-Books/b/ref=bhp_bb0309A_comint2?ie=UTF8&node=5&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=browse&pf_rd_r=0AH7GM29WF81Q72VPFDH&pf_rd_t=101&pf_rd_p=1273387142&pf_rd_i=283155
http://test-site.com (filter_var reject this!!! I have domain names with dashes )
INVALID
- http://www (php filter_var allow this, yes i know is a
valid
url) - http://www..des (php filter_var allow this)
- Any url with not allowed characters in the domain name
For completeness here is my php version: 5.3.2-1ubuntu4.2