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