title: Best Practice for Validating URLs
body: <p>I have a form to get some urls from users. Eg: Web Address, Facebook Address, Twitter Address, Google+ address etc... My problem is how I validate these urls when they submit the form. I tried to validate URL in PHP by using the FILTER_VALIDATE_URL or simply, using regular expression.</p>
  
  <p>Here, I would like to know what are the best methods to get such a urls from users. Is it always good to let them to enter protocol? sometimes they may not know it is http, https, ftp, ftps.. etc. I think it is something hard to do some users.</p>
  
  <p>I tried something like this using FILTER_VALIDATE_URL, But it always use protocol and sometime I am confusing how its work..</p>
  
  <pre><code>// validate url
  $url = 'http://www.example.com';
  
  if (filter_var( $url, FILTER_VALIDATE_URL)){
      echo "&lt;br&gt;valid";
  } else {
      echo "&lt;br&gt;invalid";
  }
  </code></pre>
  
  <p>OUTPUT : valid</p>
  
  <pre><code>// validate url
  $url = 'hp://www.example.com';
  
  if (filter_var( $url, FILTER_VALIDATE_URL)){
      echo "&lt;br&gt;valid";
  } else {
      echo "&lt;br&gt;invalid";
  }
  </code></pre>
  
  <p>OUTPUT : valid</p>
  
  <pre><code>// validate url
  $url = 'http://example.com';
  
  if (filter_var( $url, FILTER_VALIDATE_URL)){
      echo "&lt;br&gt;valid";
  } else {
      echo "&lt;br&gt;invalid";
  }
  </code></pre>
  
  <p>OUTPUT : valid</p>
  
  <pre><code>// validate url
  $url = 'http://example.com?id=32&amp;name=kamalani';
  
  if (filter_var( $url, FILTER_VALIDATE_URL)){
      echo "&lt;br&gt;valid";
  } else {
      echo "&lt;br&gt;invalid";
  }
  
  OUTPUT : valid
  </code></pre>
  
  <p>Can you tell me what are the best ways to get urls from user and how those validate?</p>
  
  <p>Any comments are greatly appreciating..</p>
  
  <p>Thank you. </p>