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 <li></li>
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.
Here's the form processor file
$name = $_POST[ 'name' ];
$guests = $_POST[ 'guests' ];
$data = "$name $guests";
$open = fopen("list.txt", "a");
fwrite($open, $data);
fclose($open);
PHP Output File
$file = "list.txt";
$open = fopen($file, 'r');
$data = fread($open, filesize($file));
fclose($open);
$list = explode("", $data);
$string = str_replace("", "", $list);
foreach($string as $value) {
echo '<li>'.ucwords($value).'</li>'."
";
}
And here is how the markup looks from the PHP output
<li>Person One 1</li>
<li>Person Two 4</li>
<li>Person Three 2</li>
<li></li>
Any help would be greatly appreciated.