Forum Moderators: coopster
$listFile = "add2db.txt";
if (!($fp = fopen($listFile, "r")))
exit("Unable to open the input file, $listFile.");
$buffer = fread($fp, filesize($listFile));
fclose($fp);
The very last character in that $listFile will always be a comma. What I need to do is remove that last comma (and only that comma) from $buffer before I can continue on. What do I need to do to accomplish this?
and the last comma is still there. Any other ideas?
if($buffer[($len = strlen($buffer)-1)] == ',') $buffer[$len] = '';
Added:
Or it could be because of a newline or eof so try changing rtrim to
$buffer = rtrim($buffer, "\n,");
[edited by: Glacai at 3:18 am (utc) on June 19, 2004]
The very last character in that $listFile will always be a comma. What I need to do is remove that last comma (and only that comma) from $buffer before I can continue on. What do I need to do to accomplish this?
Since there will always be a 'comma' at the end, you can try this ...
$buffer = substr($buffer, 0, strlen($buffer)-1);
It gets the first character of $buffer up to the end minus that 1 character which is the 'comma'.