title: Validate a URL PHP
body: <p>I've working on a project and in this project i need to check the user input is a valid URL. </p>
  
  <p>I've made a preg_match for all possible characters used on a URL. However, I'm trying to make it show an error if HTTP:// / HTTPS:// is not in front of the URL. </p>
  
  <p>Here is what I've done. </p>
  
  <pre><code>if(preg_match('/[^0-9a-zA-Z.\-\/:?&amp;=#%_]/', $url) || substr($url, 0, 7) != "http://" || substr($url, 0, 8) != "https://") {
  </code></pre>
  
  <p>But that doesn't work. It keeps giving me the an OK message. I'm not sure what I'm doing wrong here, I hope I can get some help!</p>
  
  <p>The if statement will return true or false. So </p>
  
  <pre><code>    if(preg_match('/[^0-9a-zA-Z.\-\/:?&amp;=#%_]/', $url) || substr($url, 0, 7) != "http://" || substr($url, 0, 8) != "https://") {
  echo "true";
  } else {
  echo "false";
  }
  </code></pre>
  
  <p>I just need to check if the url has entered a valid url. I don't need to verify it. Just need to check if it has HTTP:// or HTTPS:// and contains valid URL characters. </p>