title: PHP - Append only if match found in txt-file
body: <p>complete newbie to php here.
  I have a simple application where I register different accesscodes. I've already written a function that checks the txt-file for duplicates, so that only new unique values are appended. This function works fine, see below.</p>
  <pre><code>function checkAccesscode($code)
  {
      $file=fopen (&quot;files/codes.txt&quot;, 'r');
         while ($string=fgets ($file))
        {
           if ($string!=&quot;&quot;)
              {
               $part=explode (&quot;;&quot;,$string);
               $input=trim($part[0]);
  
          if (stripos($input,$code)!==false)
          {
              return true;
          }
              }
          else
          {
              return false;
          }
        }
  }
  </code></pre>
  <p>Now, what I need is a similar, separate function which also checks for matches in a different txt-file (call it &quot;codereg.txt&quot;). Meaning that the code not only has to be unique, but it also has to be pre-registered in a different application/txt-file before it can be appended to its file.</p>
  <p>Can anyone point me in the right direction?</p>
  <p>Regards,
  MadBer</p>