title: Using file() + CURL function in a foreach loop in PHP
body: <p>When I run the code below, it displays only the web page accessible through the last url listed in "domainslist.txt".  It does not display the earlier web pages.  </p>
  
  <p>For example, if "domainslist.txt" contains:</p>
  
  <pre><code>http://example[1].com
  http://example[2].com
  http://example[3].com
  </code></pre>
  
  <p>Then the code only displays the web page from example[3].com.</p>
  
  <p>Why does it not display all three?</p>
  
  <pre><code>function url_get_contents($Url) {
          if (!function_exists('curl_init')) {
              die('CURL is not installed!');
          }
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $Url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          $output = curl_exec($ch);
          curl_close($ch);
          return $output;
      }
  
      $urls = file("domainslist.txt", FILE_SKIP_EMPTY_LINES);
  
      foreach ($urls as $url) {
  
          echo(url_get_contents($url)); 
  
      }
  </code></pre>
  
  <p>NB If I create the array of URLs manually, like this:</p>
  
  <pre><code>$urls = array();
  $urls[0] = "http://example[1].com";
  $urls[1] = "http://example[2].com";
  $urls[2] = "http://example[3].com";
  </code></pre>
  
  <p>then it works fine, displaying all 3 pages.</p>
  
  <p>EDIT:</p>
  
  <p>When I used <code>var_dump($urls);</code> there is a small difference between the results from the two different methods of forming the arrays.  The first two URLs in the array created using <code>file()</code> have two extra characters reported in the string length - but the final URL (the one that displays) is the the right number of characters.  However, when the array is created manually, there are no extra characters.</p>