title: Extra list item in a PHP foreach loop
body: <p>Working on a basic "form to text file" evite list type of thing.  Everything on it works great except that it's inserting an empty <code>&lt;li&gt;&lt;/li&gt;</code> at the bottom of the list.  I'm using a carriage return delimiter and have tried using str_replace to remove the carriage return from the loop. But it's not quite working.  Is there something I'm missing on this?  Or any suggestions how to remove that bugger.</p>
  
  <p>Here's the form processor file</p>
  
  <pre><code>$name = $_POST[ 'name' ];
  $guests = $_POST[ 'guests' ];
  $data = "$name $guests\r";
  $open = fopen("list.txt", "a");
  fwrite($open, $data);
  fclose($open);
  </code></pre>
  
  <p>PHP Output File</p>
  
  <pre><code>    $file = "list.txt";
      $open = fopen($file, 'r');
      $data = fread($open, filesize($file));
      fclose($open);
  
      $list = explode("\r", $data);
      $string = str_replace("\r", "", $list);
  
      foreach($string as $value) {
          echo '&lt;li&gt;'.ucwords($value).'&lt;/li&gt;'."\n";
      }
  </code></pre>
  
  <p>And here is how the markup looks from the PHP output</p>
  
  <pre><code>&lt;li&gt;Person One 1&lt;/li&gt;
  &lt;li&gt;Person Two 4&lt;/li&gt;
  &lt;li&gt;Person Three 2&lt;/li&gt;
  &lt;li&gt;&lt;/li&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>