title: how to prepend www if the url string does not has www?
body: <p>In my website I have one form in that have one URL input field, so I want to check when ever the user entered url like the following combination <a href="http://example.com" rel="nofollow">http://example.com</a> or www.example.com or example.com. But i want to store in my database as <a href="http://www.example.com" rel="nofollow">http://www.example.com</a>. How can i do that using PHP not using .htaccess or jquery or javascript validation. </p>
  
  <pre><code>// Check, if not have http:// or https:// then prepend it
  if (!preg_match('#^http(s)?://#', $url))
  {
  $url = 'http://' . $url;
  } 
  </code></pre>
  
  <p>and the following code checked url validation </p>
  
  <pre><code>if (filter_var($source_url, FILTER_VALIDATE_URL) === FALSE)
  {
      echo "&lt;p class='error'&gt;Oops! You Forgot to Enter Website URL&lt;/p&gt;";
  }
  </code></pre>