Advice, dealing with a comma

DonnaB

New Member
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:\[code\]001,003,005,\[/code\]I then use a foreach loop to get these poll ID's from the text file. 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:\[code\]Warning: Invalid argument supplied for foreach() in\[/code\]How can i ensure that list of ID's never ends with a comma, or that it gets ignored? Like this:\[code\]001,003,005\[/code\]This is how I currently add the ID: The ID is the time plus 'tpid':\[code\] if ($handle2) { fwrite($handle2, "tpid".time().","); fclose($handle2); }\[/code\]So here i add the comma fwrite($handle2, "tpid".time().",");And I get the ID's from the text file like so:\[code\]$pollids = "pollids.txt";$contents = file_get_contents($pollids);$pollfields = explode(',', $contents);\[/code\]
 
Back
Top