title: Text file into PHP array & search for string
body: <p>I've searched long and hard for an answer to doing this &amp; have come up with nothing. I know someone here will have an answer.</p>
  
  <p>First, I get the URL and grab the subsite out of the beginning:</p>
  
  <pre><code>&lt;?php
  // get page URL
      $pageURL = 'http';
      if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
      $pageURL .= "://";
      if ($_SERVER["SERVER_PORT"] != "80") {
          $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
      } else {
          $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
      }
  // get host name from URL
      $url = preg_replace('(https?://)', '', $pageURL);
      $affUrl = explode('.', $url);
      $aff = $affUrl[0];
  ?&gt;
  </code></pre>
  
  <p>If the URL is <code>affiliate1.domain.com</code>, this returns <code>affiliate1</code> as <code>$aff</code>.</p>
  
  <p>Next, I have <code>affiliates.txt</code> each with a different name on each line:</p>
  
  <pre><code>affiliate1
  affiliate2
  affiliate-3 (yes, this is correct)
  </code></pre>
  
  <p>Then, I read that file into an array:</p>
  
  <pre><code>&lt;?php
  // read affiliates.txt and create array
      $affs = file("affiliates.txt"); 
  
  // search for affiliate in array
      $inarray = array_search($aff, $affs); // i've tried in_array() also
      if ($inarray !== false) echo '&lt;img src="affiliatelogos/$aff.jpg" class="aff-img" alt="$aff" /&gt;';
  ?&gt;
  </code></pre>
  
  <p>However, even when I hardcode an affiliate name into <code>array_search()</code>:</p>
  
  <pre><code>    $inarray = array_search('affiliate1', $affs);
  </code></pre>
  
  <p>It returns nothing. <strong>What am I doing wrong here?</strong></p>