Advice, dealing with a comma
<p>I have a script which allows the user to create a simple poll, each poll's ID is stored in a text file seperated by a comma: like so:</p>

<pre><code>001,003,005,
</code></pre>

<p>I then use a foreach loop to get these poll ID's  from the text file. </p>

<p>All relativly simple, however the way in which I create the row of text in the file always add's a comma <code>(,)</code> at the end of each ID. This throws the following error for PHP:</p>

<pre><code>Warning: Invalid argument supplied for foreach() in
</code></pre>

<p>How can i ensure that list of ID's never ends with a comma, or that it gets ignored? Like this:</p>

<pre><code>001,003,005
</code></pre>

<p>This is how I currently add the ID: The ID is the time plus 'tpid':</p>

<pre><code>    if ($handle2) {
        fwrite($handle2, "tpid".time().",");
        fclose($handle2);
    }
</code></pre>

<p>So here i add the comma fwrite($handle2, "tpid".time().",");</p>

<p>And I get the ID's from the text file like so:</p>

<pre><code>$pollids  = "pollids.txt";
$contents = file_get_contents($pollids);
$pollfields = explode(',', $contents);
</code></pre>
