title: PHP Finding a domain name and domain extension from an array
body: <p>I have an array of data containing some domains with TLD extensions. I want to collect the domain name and TLD extension seperately.</p>
  
  <p>E.g. From "hello.com" I want to collect "hello" as one variable, and then collect ".com" as another variable.</p>
  
  <p>Another E.g. IMPORTANT, from "hello.co.uk" I want to collect "hello" as one variable, and then collect ".co.uk" as another variable.</p>
  
  <p>My current code using pathinfo() will work correctly on "hello.com", but not "hello.co.uk". For "hello.co.uk" it will collect "hello.co" as one variable, and then collect ".uk" as another variable.</p>
  
  <p>Here is the code I am using:</p>
  
  <pre><code>// Get a file into an array
  $lines = file($_FILES['file']['tmp_name']);
  
  // Loop through array
  foreach ($lines as $line_num =&gt; $line) {
      echo $line;
  
      //Find TLD
      $tld = ".".pathinfo($line, PATHINFO_EXTENSION);
      echo $tld;
  
      //Find Domain
      $domain = pathinfo($line, PATHINFO_FILENAME);
      echo $domain;
      }
  </code></pre>
  
  <p>Hopefully I explained that well enough.
  I use stackoverflow a lot but couldn't find a specific example of this.</p>
  
  <p>Thanks</p>