Reputation: 11
My end result is to have a fixed length record created from either a csv of excel file using PHP. I have am working with excel_reader2.php and seems to import this nicely and displays it in the browser. I would like in turn to export or write the contents to a file so that each column would export as 35 characters fixed length fields . currently the $data is formatted as html and dont know how to write down what i am describing. Thank you in advance for someone to point me in the correct direction.
Upvotes: 1
Views: 2177
Reputation: 1686
You would take every row of the CSV file. Then, every column of the row. For every cell you could use:
$newcell = sprintf("[%35s]\n", $cell);
So you would have a 35 chars width string with the data of $cell. And then, just add it via two loops into a file.
Upvotes: 2