title: Using preg_match to discover and validate types of links embedded in html
body: <p>I have implemented a function to validate .edu domains. This is how I am doing it:</p>
  
  <pre><code>if( preg_match('/edu/', $matches[0])==FALSE )
      return FALSE;
  return TRUE;
  </code></pre>
  
  <p>Now I want to skip those urls as well that point to some documents such as .pdf and .doc.</p>
  
  <p>For this, the following code should have worked but is not:</p>
  
  <pre><code>if( preg_match('/edu/', $matches[0])==FALSE || preg_match('/pdf/i', $matches[0])!=FALSE || preg_match('/doc/i', $matches[0]!=FALSE))
          return FALSE;
  return TRUE;
  </code></pre>
  
  <p>Where am I wrong in this regard?
  Moreover, how will I implement preg_match in such a way that it has a list of document types to check in a url string. If a certain type of document is found, it should return false. In other words, I want to provide a list (an array maybe) of various document types as $pattern to find in a url.</p>
  
  <blockquote>
    <p>Note:
    matches[0] contains the whole url string.
    eg: <a href="http://www.nust.edu.pk/Documents/pdf/NNBS_Form.pdf" rel="nofollow">http://www.nust.edu.pk/Documents/pdf/NNBS_Form.pdf</a></p>
  </blockquote>
  
  <p>The code for the function:</p>
  
  <pre><code>public function validateEduDomain($url) {
      // get host name from URL
      preg_match('@^(?:http://)?([^/]+)@i', $url, $matches);
      $host = $matches[1];
  
      // get last two segments of host name
      preg_match('/[^.]+\.[^.]+$/', $host, $matches);
  
      if( preg_match('/edu/', $matches[0])!=FALSE &amp;&amp; (preg_match('/pdf/i', $matches[0])==FALSE || preg_match('/doc/i', $matches[0]==FALSE)))      
          return TRUE;
      return FALSE;
  }
  </code></pre>