I have a space delimited file that I need to do a little manipulation of an then convert to a comma separated file. I have the conversion working alright, but I'm not sure of the manipulation?
The rows look like this:
9780002005531 2 0 0 1 41.N
And I'd like to have them look like this:
9780002005531,2,0,0,1,41.00,N
The second last field will always have two decimal places appended.
The code I have for conversion is like so:
$lines = file($opt['i']);
foreach ($lines as $line) {
$line = preg_split("/ /", $line);
foreach ($line as $field) {
$field = chop($field);
if ($field != "") {
fwrite($fh, "$field,");
}
}
fwrite($fh, "\n");
}
I'm just not sure where, and how, to do the manipulation?
Thanks in advance.