Re: Send .csv file to browser [message #170030 is a reply to message #170014] |
Wed, 06 October 2010 09:01 |
Captain Paralytic
Messages: 204 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 5 Oct, 17:05, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 10/5/2010 10:55 AM, sheldonlg wrote:
>
>
>
>
>
>> On 10/5/2010 10:20 AM, Derek Turner wrote:
>>> On Tue, 05 Oct 2010 14:19:04 +0000, Derek Turner wrote:
>
>>>> 3. Use appropriate header files and then readfile()
>
>>> Sorry lines/statements
>
>> Why not simply
>
>> $theData = getDataFromTableAsArrayOfNonAssociativeArrays();
>> foreach ($theData as $rec) {
>> $line = implode(',', $rec);
>> print $line . '<br>';
>> }
>
>> The user can then cut and paste it into a file or you can put in code
>> for the user to download that piece.
>
>> Another approach is to output an Excel file and the user can then output
>> from that Excel file to a .csv file.
>
> Right idea, but some problems. First of all, what happens if a field
> contains a comma i.e. "Smith, Jr.". Text fields also need to be
> surrounded by double quotes, and any double quotes in the text field
> must be doubled to be a valid CSV file. Also, some places use a
>
> Not hard - just a matter of looking at each field, and if it is numeric,
> insert it in the stream. If it is text, replace all occurrences of '"'
> with '""' and insert it with surrounding quotes. Of course, use commas
> to separate the fields.
>
> Then just output directly with the appropriate headers.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Whenever I can, I substitute tab delimited for comma delimited as it
tends to bypass most of these problems (particularly around Excel
which is not capable of correctly handling csv - or even tab delimited
- data properly)
|
|
|