title: php preg_match, not working for validating URL's
body: <p>Ihave a PHP preg_match regex which is : </p>
  
  <pre><code>#^(http:\/\/|https:\/\/|www\.|//)*(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d{1,5}))?([A-Z0-9_-]|\.|\/|\?|\#|=|&amp;|%)*$#i
  </code></pre>
  
  <p>The problem is when I try to match any URL ending with .com&amp;&amp; , it returns true, but as expected it should return false, what could be possibly wrong with it? </p>
  
  <p>I am using it as:</p>
  
  <pre><code>    function isValidURL($url) {
          if (preg_match("#^(http:\/\/|https:\/\/|www\.|//)*(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d{1,5}))?([A-Z0-9_-]|\.|\/|\?|\#|=|&amp;|%)*$#i", $url)) {
              return true;
          }else{
              return false;
          }
      }
  </code></pre>
  
  <p>and accessing it as:</p>
  
  <pre><code>$URL = $_GET['url'];
  echo var_dump(isValidURL($URL));
  </code></pre>
  
  <p>Now if I open the page as <code>/url.php?url=http://www.google.com</code> it returns true, if I open page as <code>/url.php?url=http://www.google.com**</code> it returns false.  If I open the page as <code>/url.php?url=http://www.google.com&amp;&amp;</code> it returns true but it should return false as .com&amp;&amp; is not a valid TLD.</p>